babel-jest

VueJS - Unit testing with vue-test-utils gives error - TypeError: _vm.$t is not a function

前提是你 提交于 2019-12-06 00:09:42
问题 Relatively new to Vuejs and testing its components. Using vue-test-utils and jest for testing. Getting following error test log The .vue file consists of template, component and styling. Below is the part of the SignupLayout.vue that gets error - <style lang="sass"> @import '../stylesheets/colors' html[path="/signup"], html[path="/login"] height: 100% background-image: url("../assets/background.jpg") background-size: cover background-position: center background-repeat: no-repeat overflow:

Configuring Babel and Jest

泪湿孤枕 提交于 2019-12-05 17:34:26
TLDR: How can I configure jest so that it uses babel to compile the test files and the files required in globalSetup and globalTeardown ? I've been struggling a lot to configure jest and babel . It seems that when I run my tests babel fails to load the configuration file, or perhaps it doesn't run at all. in package.json: { "scripts": { "start": "babel-node src/index.js", "test": "jest src/tests/*.test.js", }, "devDependencies": { "@babel/cli": "^7.0.0-rc.1", "@babel/core": "^7.0.0-rc.1", "@babel/node": "^7.0.0-rc.1", "@babel/preset-env": "^7.0.0-rc.1", "babel-jest": "^23.4.2", "jest": "^23.5

What is the difference between babel-core and @babel/core?

落花浮王杯 提交于 2019-12-04 23:43:41
What is the difference between babel-core and @babel/core ? Are they the same thing but different versions? If not so, when do you use one and when do you use the other? Thank you. Since Babel 7 the Babel team switched to scoped packages , so you now have to use @babel/core instead of babel-core . But in essence, @babel/core is just a newer version of babel-core . This is done to make a better distinction which packages are official and which are third-party. 来源: https://stackoverflow.com/questions/53380741/what-is-the-difference-between-babel-core-and-babel-core

VueJS - Unit testing with vue-test-utils gives error - TypeError: _vm.$t is not a function

你离开我真会死。 提交于 2019-12-04 07:46:55
Relatively new to Vuejs and testing its components. Using vue-test-utils and jest for testing. Getting following error test log The .vue file consists of template, component and styling. Below is the part of the SignupLayout.vue that gets error - <style lang="sass"> @import '../stylesheets/colors' html[path="/signup"], html[path="/login"] height: 100% background-image: url("../assets/background.jpg") background-size: cover background-position: center background-repeat: no-repeat overflow: hidden #signup-layout #change-language-button .lang-menu color: $alto </style> Test File - import Vue from

“Define is not defined” in Jest when testing es6 module with RequireJS dependency

混江龙づ霸主 提交于 2019-12-04 02:11:13
I have a Jest test suite that fails to run because the component it's trying to test depends on a RequireJS module. Here's the error I'm seeing: FAIL __tests__/components/MyComponent.test.js ● Test suite failed to run ReferenceError: define is not defined at Object.<anonymous> (node_modules/private-npm-module/utils.js:1:90) The component has the following import: import utils from 'private-npm-module'; And the private-npm-module is set up like so: define('utils', [], function() { return {}; }); When MyComponent is transpiled with babel and run in the browser, the dependency operates correctly.

reactjs jest jQuery is not defined

只愿长相守 提交于 2019-12-03 22:37:02
I am using jest to test my reactJS component. In my reactJS component, I need to use jquery UI, so I added this in the component: var jQuery = require('jquery'); require('jquery-ui/ui/core'); require('jquery-ui/ui/draggable'); require('jquery-ui/ui/resizable'); And it worked fine. But, now, I need to used jest to do testing, but I immediately meet this issue when I load the component into testutils, Test suite failed to run ReferenceError: jQuery is not defined Has anyone met this issue if you are using jQuery in your app? Thanks You can add jQuery dependency in your global object. Do the

How does jest allow mutation of modules?

元气小坏坏 提交于 2019-12-01 04:12:21
In this question that I asked here: Why does mutating a module update the reference if calling that module from another module, but not if calling from itself? I'm asking about the nature of module mutation. However as it it turns out, ES6 modules can't actually be mutated - all of their properties are treated as constants. ( See this answer ) But somehow - when Jest tests modules - they can be mutated, and that's how Jest allows for mocking. How is this happening? I imagine that it's a babel plugin that that's running - transpiling the module to CommonJS modules? Is there any documentation

How does jest allow mutation of modules?

丶灬走出姿态 提交于 2019-12-01 01:50:01
问题 In this question that I asked here: Why does mutating a module update the reference if calling that module from another module, but not if calling from itself? I'm asking about the nature of module mutation. However as it it turns out, ES6 modules can't actually be mutated - all of their properties are treated as constants. (See this answer) But somehow - when Jest tests modules - they can be mutated, and that's how Jest allows for mocking. How is this happening? I imagine that it's a babel

Does Jest support ES6 import/export?

我只是一个虾纸丫 提交于 2019-11-28 22:54:41
If I use import/export from ES6 then all my jest tests fail with error: Unexpected reserved word I convert my object under test to use old school IIFY syntax and suddenly my tests pass. Or, take an even simpler test case: var Validation = require('../src/components/validation/validation');//PASS //import * as Validation from '../src/components/validation/validation'//FAIL Same error. Obviously there's a problem with import/export here. It's not practical for me to rewrite my code using ES5 syntax just to make my test framework happy. I have babel-jest. I tried various suggestions from github

Mocking `document` in jest

回眸只為那壹抹淺笑 提交于 2019-11-27 13:07:21
I'm trying to write tests for my web components projects in jest. I already use babel with es2015 preset. I'm facing an issue while loading the js file. I have followed a piece of code where document object has a currentScript object. But in test context it is null . So I was thinking of mocking same. But jest.fn() is not really help in same. How can I handle this issue? Piece of code where jest is failing. var currentScriptElement = document._currentScript || document.currentScript; var importDoc = currentScriptElement.ownerDocument; Test case I have written. component.test.js import * as