jestjs

jest how set file pattern in package.json script

岁酱吖の 提交于 2020-08-19 16:44:45
问题 I have in packadge.json "scripts": { "test": "cross-env NODE_ENV=test jest" }, I want to test all files match pattern front/**/*.test.js but if "scripts": { "test": "cross-env NODE_ENV=test jest \"front/**/*.test.js\"" }, I've got an error Invalid testPattern front/**/*.test.js supplied. Running all tests instead. So, how could I pass file names pattern to jest? Thanks. 回答1: According to the documentation you are supposed to use a regex for your pattern. So in your case you probably would

jest how set file pattern in package.json script

冷暖自知 提交于 2020-08-19 16:44:14
问题 I have in packadge.json "scripts": { "test": "cross-env NODE_ENV=test jest" }, I want to test all files match pattern front/**/*.test.js but if "scripts": { "test": "cross-env NODE_ENV=test jest \"front/**/*.test.js\"" }, I've got an error Invalid testPattern front/**/*.test.js supplied. Running all tests instead. So, how could I pass file names pattern to jest? Thanks. 回答1: According to the documentation you are supposed to use a regex for your pattern. So in your case you probably would

jest how set file pattern in package.json script

十年热恋 提交于 2020-08-19 16:43:06
问题 I have in packadge.json "scripts": { "test": "cross-env NODE_ENV=test jest" }, I want to test all files match pattern front/**/*.test.js but if "scripts": { "test": "cross-env NODE_ENV=test jest \"front/**/*.test.js\"" }, I've got an error Invalid testPattern front/**/*.test.js supplied. Running all tests instead. So, how could I pass file names pattern to jest? Thanks. 回答1: According to the documentation you are supposed to use a regex for your pattern. So in your case you probably would

Get the current test/spec name in Jest

雨燕双飞 提交于 2020-08-19 12:28:27
问题 Is there a way to get the current spec name from within the running test? Basically I want to save a file, eg. using a function saveFile() , with the name of the file being the spec name. Without having to manually retype the name of the test. 回答1: I found that the only possible way was through the use of expect() , which contains the spec name in its this . doing something like expect.extend({ async toSaveFile(data) { fs.writeFileSync(`${this.currentTestName}.txt`, data) return { pass: true

Get the current test/spec name in Jest

依然范特西╮ 提交于 2020-08-19 12:25:34
问题 Is there a way to get the current spec name from within the running test? Basically I want to save a file, eg. using a function saveFile() , with the name of the file being the spec name. Without having to manually retype the name of the test. 回答1: I found that the only possible way was through the use of expect() , which contains the spec name in its this . doing something like expect.extend({ async toSaveFile(data) { fs.writeFileSync(`${this.currentTestName}.txt`, data) return { pass: true

Get the current test/spec name in Jest

人走茶凉 提交于 2020-08-19 12:24:30
问题 Is there a way to get the current spec name from within the running test? Basically I want to save a file, eg. using a function saveFile() , with the name of the file being the spec name. Without having to manually retype the name of the test. 回答1: I found that the only possible way was through the use of expect() , which contains the spec name in its this . doing something like expect.extend({ async toSaveFile(data) { fs.writeFileSync(`${this.currentTestName}.txt`, data) return { pass: true

Override Object Property for unit testing purposes

生来就可爱ヽ(ⅴ<●) 提交于 2020-08-10 22:54:17
问题 I am using Jest to perform unit tests on a Node.js app, where the code source is written in TypeScript and then compiled into JavaScript. In one of the classes that I wish to test, an external module is imported and a method from this module is used. I want to mock the calls to this method, in order to test only my code. However, when I run the test, I get the following error: TypeError: Cannot redefine property: methodName The problem is that this method has the following Object Properties:

Override Object Property for unit testing purposes

我的梦境 提交于 2020-08-10 22:54:14
问题 I am using Jest to perform unit tests on a Node.js app, where the code source is written in TypeScript and then compiled into JavaScript. In one of the classes that I wish to test, an external module is imported and a method from this module is used. I want to mock the calls to this method, in order to test only my code. However, when I run the test, I get the following error: TypeError: Cannot redefine property: methodName The problem is that this method has the following Object Properties:

Fail to trigger Vuetify form submit using submit button in Jest

你。 提交于 2020-08-10 21:15:20
问题 I'm trying to verify the behavior of a Vue form, based on Vuetify components, using Jest and Avoriaz. I can trigger submit.prevent on the form, resulting in expected behavior. But triggering click on the submit button does not work. The component: <template> <v-form ref="form" data-cy="form" @submit.prevent="login" > <v-text-field id="email" v-model="email" label="Email" name="email" prepend-icon="mdi-at" type="text" required autofocus data-cy="email-text" /> <v-btn color="primary" type=

Fail to trigger Vuetify form submit using submit button in Jest

点点圈 提交于 2020-08-10 21:14:58
问题 I'm trying to verify the behavior of a Vue form, based on Vuetify components, using Jest and Avoriaz. I can trigger submit.prevent on the form, resulting in expected behavior. But triggering click on the submit button does not work. The component: <template> <v-form ref="form" data-cy="form" @submit.prevent="login" > <v-text-field id="email" v-model="email" label="Email" name="email" prepend-icon="mdi-at" type="text" required autofocus data-cy="email-text" /> <v-btn color="primary" type=