This repository was archived by the owner on Mar 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +286
-16
lines changed Expand file tree Collapse file tree 10 files changed +286
-16
lines changed Original file line number Diff line number Diff line change 11{
2+ "sourceType" : " unambiguous" ,
23 "presets" : [
34 " @babel/preset-env" ,
45 " @babel/preset-react" ,
5- {
6- "plugins" : [" @babel/plugin-proposal-class-properties" ]
7- },
6+ // {
7+ // "plugins": ["@babel/plugin-proposal-class-properties"]
8+ // },
89 " @emotion/babel-preset-css-prop"
910 ],
11+ "plugins" : [" @babel/plugin-proposal-class-properties" ],
1012 "env" : {
1113 // TODO switch this to "development" name
12- "test " : {
14+ "development " : {
1315 "plugins" : [
1416 // during Cypress tests we want to instrument source code
1517 // to get code coverage from tests
16- " babel-plugin-istanbul" ,
18+ // "babel-plugin-istanbul"
1719 // we also want to export ES6 modules as objects
1820 // to allow mocking named imports
1921 [
2022 " @babel/plugin-transform-modules-commonjs" ,
2123 {
24+ "allowCommonJSExports" : true ,
2225 "loose" : true
2326 }
2427 ]
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import React from 'react'
3+ import { getRandomNumber } from './calc'
4+
5+ const Component = ( ) => {
6+ const n = getRandomNumber ( )
7+ return < div className = "random" > { n } </ div >
8+ }
9+
10+ export default Component
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ import React from 'react'
3+ import { mount } from 'cypress-react-unit-test'
4+ import Component from './Component.jsx'
5+ import * as calc from './calc'
6+
7+ describe ( 'Component' , ( ) => {
8+ it ( 'mocks call from the component' , ( ) => {
9+ cy . stub ( calc , 'getRandomNumber' )
10+ . as ( 'lucky' )
11+ . returns ( 777 )
12+ mount ( < Component /> )
13+ } )
14+ } )
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ const React = require ( 'react' )
3+ const { getRandomNumber } = require ( './calc' )
4+
5+ const Component = ( ) => {
6+ const n = getRandomNumber ( )
7+ return < div className = "random" > { n } </ div >
8+ }
9+
10+ module . exports = Component
Original file line number Diff line number Diff line change 1+ /// <reference types="cypress" />
2+ const React = require ( 'react' )
3+ const { mount } = require ( 'cypress-react-unit-test' )
4+ const Component = require ( './ComponentReq.jsx' )
5+ const calc = require ( './calc' )
6+
7+ describe ( 'Component' , ( ) => {
8+ it ( 'mocks call from the component' , ( ) => {
9+ cy . stub ( calc , 'getRandomNumber' )
10+ . as ( 'lucky' )
11+ . returns ( 777 )
12+ mount ( < Component /> )
13+ } )
14+ } )
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import * as calc from './calc'
66
77describe ( 'Mocking' , ( ) => {
88 // https://github.com/bahmutov/cypress-react-unit-test/issues/266
9- it . skip ( 'mocks import used by the Post' , ( ) => {
9+ it ( 'mocks import used by the Post' , ( ) => {
1010 cy . stub ( calc , 'getRandomNumber' )
1111 . as ( 'lucky' )
1212 . returns ( 777 )
Original file line number Diff line number Diff line change 1+ import * as calc from './calc'
2+
3+ // checking mocked value if there is no React involved
4+ describe ( 'plain' , ( ) => {
5+ it ( 'mocks es6 import' , ( ) => {
6+ cy . stub ( calc , 'getRandomNumber' )
7+ . as ( 'lucky' )
8+ . returns ( 777 )
9+
10+ cy . then ( ( ) => {
11+ return calc . getRandomNumber ( )
12+ } ) . should ( 'equal' , 777 )
13+ } )
14+ } )
Original file line number Diff line number Diff line change 121121 "url" : " https://github.com/bahmutov/cypress-react-unit-test.git"
122122 },
123123 "dependencies" : {
124- "@babel/plugin-transform-modules-commonjs" : " 7.7.5 " ,
124+ "@babel/plugin-transform-modules-commonjs" : " 7.10.1 " ,
125125 "@cypress/code-coverage" : " 3.8.1" ,
126126 "@cypress/webpack-preprocessor" : " 5.4.1" ,
127127 "babel-plugin-istanbul" : " 6.0.0" ,
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ module.exports = config => {
5959
6060 const wpPreprocessorOptions = webpackPreprocessor . defaultOptions
6161 enableBabelrc ( wpPreprocessorOptions . webpackOptions )
62+ debug ( 'webpack options %o' , wpPreprocessorOptions . webpackOptions )
6263
6364 addImageRedirect ( wpPreprocessorOptions . webpackOptions )
6465
You can’t perform that action at this time.
0 commit comments