jestjs

How to test vue router beforeRouteUpdate navigation guard?

一笑奈何 提交于 2021-02-10 14:32:23
问题 First off, I'm using Vue-property-decorator. My component has a component route, defined like this. @Component({ components: { ComponentA, ComponentB }, beforeRouteUpdate (to, _from, next) { const { checkInDate, checkOutDate, items, currency, locale } = to.query; const queryFullfilled = !!checkInDate && !!checkOutDate && !!items.length && !!currency && !!locale; if ([BOOKING_PAGE, RESERVATION_PAGE].indexOf(to.name) > -1 && queryFullfilled) { this.validateRooms(); } next(); } }) export default

How to test vue router beforeRouteUpdate navigation guard?

旧时模样 提交于 2021-02-10 14:32:07
问题 First off, I'm using Vue-property-decorator. My component has a component route, defined like this. @Component({ components: { ComponentA, ComponentB }, beforeRouteUpdate (to, _from, next) { const { checkInDate, checkOutDate, items, currency, locale } = to.query; const queryFullfilled = !!checkInDate && !!checkOutDate && !!items.length && !!currency && !!locale; if ([BOOKING_PAGE, RESERVATION_PAGE].indexOf(to.name) > -1 && queryFullfilled) { this.validateRooms(); } next(); } }) export default

How to check the response from global fetch in JEST test case

自闭症网瘾萝莉.ら 提交于 2021-02-10 14:18:43
问题 So, i am using jest for testing my node function which is calling fetch() APi to get the data, now when I am writing the test cases for the same i am getting an error like : expect(received).resolves.toEqual() Matcher error: received value must be a promise Received has type: function Received has value: [Function mockConstructor] my function : export function dataHandler (req, res, next) { const url= "someURL" if (url ) { return fetch(url ) .then((response) => response.json()) .then(

MongoError: pool is draining, new operations prohibited when using MongoMemoryServer in integration test

情到浓时终转凉″ 提交于 2021-02-09 11:47:33
问题 I'm using MongoMemoryServer to write an integration test. I have two integration test files. When I run the IT tests I see the following. I don't understand why. I'm using jestjs test framework. I'm seeing the following error when I have two IT test files MongoError: pool is draining, new operations prohibited 37 | for (const key in collections) { 38 | const collection = collections[key]; > 39 | await collection.deleteMany(); | ^ 40 | } 41 | }; Here is my setup //db-handler.js const mongoose

How to test that an inner function has been called from an imported function? (with Jest.js)

天大地大妈咪最大 提交于 2021-02-09 10:58:34
问题 I'm having issues with Jest testing that a closure (an inner function) has been called after calling the outer function. I've tried using the spyOn with no positive result. This seems to be a relatively simple problem, to which I haven't found any results from googling. // helper.js export const bar = () => {} export const foo = () => { bar(); //How do I test that this has been called? } //helper.test.js import * as H from 'helper'; const barSpy = jest.spyOn(H, 'bar'); H.foo(); expect(barSpy)

How to test that an inner function has been called from an imported function? (with Jest.js)

老子叫甜甜 提交于 2021-02-09 10:58:32
问题 I'm having issues with Jest testing that a closure (an inner function) has been called after calling the outer function. I've tried using the spyOn with no positive result. This seems to be a relatively simple problem, to which I haven't found any results from googling. // helper.js export const bar = () => {} export const foo = () => { bar(); //How do I test that this has been called? } //helper.test.js import * as H from 'helper'; const barSpy = jest.spyOn(H, 'bar'); H.foo(); expect(barSpy)

Unit testing of styled-components with SVG imports

旧城冷巷雨未停 提交于 2021-02-09 05:44:27
问题 I am in the process of upgrading the dependencies of a React project. I upgraded styled-components from 1.4.4 to 2.5.0-1 . I didn't expect any breaking changes since I read that styled-components v2 is a drop-in replacement for v1. I don't see any breaking changes in the web app, but my test cases are broken. Consider the following, dumb and useless test. test('does something', () => { expect(true).toBe(true); }); As expected, the test works. However, as soon as I even try to import a styled

SyntaxError: Invalid or unexpected token @import

怎甘沉沦 提交于 2021-02-09 02:45:51
问题 I am trying to add Jest and Enzyme to a React webpack project. Everything is working, until I add tests to a component, with a style sheet importing google fonts. The error I get is: ● Test suite failed to run /Users/dev/Code/Git/react-redux-webpack/src/App.sass:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){@import url('https://fonts.googleapis.com/css?family=Barlow+Condensed') ^ SyntaxError: Invalid or unexpected token The sass file looks like:

SyntaxError: Invalid or unexpected token @import

旧时模样 提交于 2021-02-09 02:45:33
问题 I am trying to add Jest and Enzyme to a React webpack project. Everything is working, until I add tests to a component, with a style sheet importing google fonts. The error I get is: ● Test suite failed to run /Users/dev/Code/Git/react-redux-webpack/src/App.sass:1 ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){@import url('https://fonts.googleapis.com/css?family=Barlow+Condensed') ^ SyntaxError: Invalid or unexpected token The sass file looks like:

Jest doesn't show stack trace

大兔子大兔子 提交于 2021-02-08 15:15:33
问题 I'm really confused, in our project jest isn't showing any stacktrace when an error appears. Following simple failing test: test('XXX', () => { expect(true).toBe(false); }); Outputs following: FAIL src/Sulu/Bundle/AdminBundle/Resources/js/containers/Form/tests/stores/XXX.test.js ● XXX expect(received).toBe(expected) // Object.is equality Expected value to be: false Received: true That's everything.. No error line.. Nothing.. We have used following things in our setup: Jest React Babel Enzyme