jestjs

import with jest error: Unexpected token import

好久不见. 提交于 2020-12-10 10:40:34
问题 I've seen similar questions but still can't find a viable solution. I'm trying to integrate Jest into a working project, which uses import/export default in hundreds of places. The following test does work for Jest using require: const bar = require('../../flows/foo'); test('adds 1 + 2 to equal 3', () => { expect(bar.foobar(1, 2)).toBe(3); }); when export is: module.exports = { foobar: foobar, fizz: fizz } The functions I'll want to be testing however are exported using: export default {

import with jest error: Unexpected token import

北城余情 提交于 2020-12-10 10:39:54
问题 I've seen similar questions but still can't find a viable solution. I'm trying to integrate Jest into a working project, which uses import/export default in hundreds of places. The following test does work for Jest using require: const bar = require('../../flows/foo'); test('adds 1 + 2 to equal 3', () => { expect(bar.foobar(1, 2)).toBe(3); }); when export is: module.exports = { foobar: foobar, fizz: fizz } The functions I'll want to be testing however are exported using: export default {

import with jest error: Unexpected token import

我与影子孤独终老i 提交于 2020-12-10 10:37:31
问题 I've seen similar questions but still can't find a viable solution. I'm trying to integrate Jest into a working project, which uses import/export default in hundreds of places. The following test does work for Jest using require: const bar = require('../../flows/foo'); test('adds 1 + 2 to equal 3', () => { expect(bar.foobar(1, 2)).toBe(3); }); when export is: module.exports = { foobar: foobar, fizz: fizz } The functions I'll want to be testing however are exported using: export default {

How to use jest.spyOn with React function component using Typescript

戏子无情 提交于 2020-12-10 08:48:06
问题 I am developing a React app using Typescript, and hooks, and I am trying to use Enzyme with Jest to test the function components. I am unable to use jest.spyOn to test a method in my component. The jest.spyOn method doesn't resolve correctly and shows following message on hover "Argument of type '"validateBeforeSave"' is not assignable to parameter of type '"context" | "setState" | "forceUpdate" | "render" | "componentDidMount" | "shouldComponentUpdate" | "componentWillUnmount" |

Sample use case to test Async Storage with Jest-expo?

别等时光非礼了梦想. 提交于 2020-12-10 07:59:09
问题 I have replicated an example to understand the testing of Mock-async-storage for reactjs. Any suggestions for a different approach of testing are welcome. I tried to replicate the use case from this stack overflow page : How to test Async Storage with Jest? but I couldn't figure out how that would fit for my sample case. So I tried the below npm module https://github.com/devmetal/mock-async-storage, but that didn't help either. Code written in Example.test.js import AsyncStorage from '@react

How to test that a media query css applies to an element upon screen resize using jest and enzyme in reactjs

为君一笑 提交于 2020-12-09 14:01:51
问题 I am trying to test the responsiveness of the application I am building in reactjs using jest and enzyme. How can I do that? I have a sidebar which transitions left and disappears when the screen size is less than or equal to 1024px. I went through this - Figuring out how to mock the window size changing for a react component test stackoverflow question to simulate/mock a screen resize. Then I tried using DOM functions like getComputedStyle to see if the css rule for transition is applied to

How to test that a media query css applies to an element upon screen resize using jest and enzyme in reactjs

前提是你 提交于 2020-12-09 14:01:06
问题 I am trying to test the responsiveness of the application I am building in reactjs using jest and enzyme. How can I do that? I have a sidebar which transitions left and disappears when the screen size is less than or equal to 1024px. I went through this - Figuring out how to mock the window size changing for a react component test stackoverflow question to simulate/mock a screen resize. Then I tried using DOM functions like getComputedStyle to see if the css rule for transition is applied to

How to ensure Jest fails on “unhandledRejection”?

岁酱吖の 提交于 2020-12-08 06:46:33
问题 Our unit tests run in containers in our continuous delivery pipelines. Sometimes, we don't handle rejections in our unit tests, however, I don't think it's correct and in my opinion the pipeline should fail. How can I make sure that when I execute jest and during the tests an unhandledRejection event occurs, jest will exit with error? I tried to hook event listeners in a setup script: /* jest.config.js */ module.exports = { setupFiles: ['<rootDir>/test/setup.ts'], // ... } and in that setup

jest typescript property mock does not exist on type

隐身守侯 提交于 2020-12-08 05:16:23
问题 When using jest.fn() to add a mock you can usually access the .mock property to access details such as calls, something similar to this: test('not working', () => { const foo = new Foo(); foo.addListener = jest.fn(); foo.func(); // will call addListener with a callback const callback = foo.addListener.mock.calls[0][0]; expect(callback()).toEqual(1); // test the callback }); When implementing the test in typescript instead of plain javascript I get the error: error TS2339: Property 'mock' does

show correct error in jest unit test angular

那年仲夏 提交于 2020-12-05 06:59:29
问题 I am writing unit test in NX angular workspace. sometimes it is giving error like this : (node:15320) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON --> starting at object with constructor 'Object' | property 'element' -> object with constructor 'Object' | property 'componentProvider' -> object with constructor 'Object' --- property 'parent' closes the circle at stringify (<anonymous>) at writeChannelMessage (internal/child_process/serialization.js:117:20)