GithubHelp home page GithubHelp logo

Comments (5)

layershifter avatar layershifter commented on July 24, 2024

Please provide an isolated repro on Stackblitz/Github repo 🙏 It would help us to understand the issue.

from fluentui.

layershifter avatar layershifter commented on July 24, 2024

In Jest & jsdom typeof window.matchMedia returns:

console.log("window.matchMedia: typeof", typeof window.matchMedia)
// window.matchMedia: typeof undefined

And we have already a check against it:

if (targetWindow === null || typeof targetWindow.matchMedia !== 'function') {

It looks that your env mocks window.matchMedia without providing a proper implementation.

from fluentui.

GeoffCoxMSFT avatar GeoffCoxMSFT commented on July 24, 2024

@layershifter - In this case the partner is trying to unit test a dialog of their own. Our Dialog uses the reduced motion hook. When we test the hook, we mock the media queries. It seems like an unnecessary burden for callers of Dialog writing tests to have to mock all the internals of Dialog and any hooks it uses. The matchMedia returns an object but it doesn't have the add/remove event listener. If the hook checked that the add/remove event listener functions were non-null and functions like it does the matchMedia function, then the hook could return false without the partner needing to mock.

from fluentui.

layershifter avatar layershifter commented on July 24, 2024

When we test the hook, we mock the media queries. ... It seems like an unnecessary burden for callers of Dialog writing tests to have to mock all the internals of Dialog and any hooks it uses.

@GeoffCoxMSFT do I correctly understand that window.matchMedia is mocked? If so, why is that needed to test Dialog? As it's not required in the first place...

A minimal example of that unit test would help to understand a proper solution for this issue.

from fluentui.

akisnejuhasz avatar akisnejuhasz commented on July 24, 2024

Talked offline to show the affected files in the repository. In the end it was me how did not set up a mock correctly for window.matchMedia and addEventListener inside it.

Thank you @layershifter for the help!

from fluentui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.