mocha

How to test an npm module with peerDependencies?

假如想象 提交于 2020-06-27 07:31:40
问题 I am new to understand peerDependencies , and I have read the following references seeking as to how to test an npm module contains peerDependencies within its package.json: Peer Dependencies Understanding the npm dependency model Common npm mistakes StackOverflow: npm peerDependencies during development However, I have not found a clear solution for testing npm with peerDependencies. Some recommend adding the peerDependencies as globals, and some reference to include peerDependencies within

Chai unittesting - expect(42).to.be.an('integer')

扶醉桌前 提交于 2020-06-24 19:38:53
问题 According to http://chaijs.com/api/bdd/#a, a / an can be used to check for the type of a variable. .a(type) @param{ String } type @param{ String } message _optional_ The a and an assertions are aliases that can be used either as language chains or to assert a value's type. However, I'm not able to check for the variable beeing an integer. The given examples, e.g. expect('1337').to.be.a('string'); work for me, but the following does not: expect(42).to.be.an('integer'); expect(42).to.be.an(

Chai unittesting - expect(42).to.be.an('integer')

拟墨画扇 提交于 2020-06-24 19:30:29
问题 According to http://chaijs.com/api/bdd/#a, a / an can be used to check for the type of a variable. .a(type) @param{ String } type @param{ String } message _optional_ The a and an assertions are aliases that can be used either as language chains or to assert a value's type. However, I'm not able to check for the variable beeing an integer. The given examples, e.g. expect('1337').to.be.a('string'); work for me, but the following does not: expect(42).to.be.an('integer'); expect(42).to.be.an(

Mocha not exiting after test

落爺英雄遲暮 提交于 2020-06-24 05:36:27
问题 I'm starting with tests in Node. Using mocha, chai and nock (to intercept external HTTP api calls). I have written 3 tests, all of them are a pass, however, when I added the 3rd test, mocha stopped exiting after running the tests, with no error or indication of anything wrong. If I comment the 3rd test, mocha exits just fine. This is the test causing the 'issue': describe('tokenizer.processFile(req, \'tokenize\')', () => { it('should tokenize a file', async () => { req = { file: {

How to extend Mocha's Context interface?

徘徊边缘 提交于 2020-06-22 04:34:00
问题 Take the following code snippet: import { Foo } from "./foo"; export interface MyContext extends Mocha.Context { foo: Foo; } This is in a project with the @types/mocha package installed, so that the Mocha namespace can be inferred by the compiler. Now, if I try to use this interface in a test suite: import { MyContxt } from "../types/mocha"; describe("my test suite", function() { it("should do something", function(this: MyContext) { ... }); }); The TypeScript compiler throws the following

How to extend Mocha's Context interface?

强颜欢笑 提交于 2020-06-22 04:33:09
问题 Take the following code snippet: import { Foo } from "./foo"; export interface MyContext extends Mocha.Context { foo: Foo; } This is in a project with the @types/mocha package installed, so that the Mocha namespace can be inferred by the compiler. Now, if I try to use this interface in a test suite: import { MyContxt } from "../types/mocha"; describe("my test suite", function() { it("should do something", function(this: MyContext) { ... }); }); The TypeScript compiler throws the following

Mocha runs only one test

倾然丶 夕夏残阳落幕 提交于 2020-06-18 04:04:41
问题 I have a sails.js app that I want to test with mocha, in my test folder I have 2 tests, but when I run mocha only one test gets executed. Test1.js var request = require('supertest'); describe.only('UserController', function() { describe('#login()', function() { it('should redirect to /mypage', function (done) { done(); }); }); }); Test2.js describe.only('UsersModel', function() { describe('#find()', function() { it('should check find function', function (done) { done(); }); }); }); I run

How to augment @types/mocha? [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2020-06-17 15:58:05
问题 This question already has an answer here : How to extend Mocha's Context interface? (1 answer) Closed 6 days ago . I tried to apply Aluan's answer in countless different ways, but none worked, that is, none gave me the sweet auto-complete for the types that I augmented: augmentations.d.ts import { Foo } from './foo'; declare module "mocha" { namespace Mocha { export interface Context { foo: Foo; } } } I made sure that the augmentations.d.ts file is part of a glob pattern in the include

How to stub Vue component methods for unit testing

微笑、不失礼 提交于 2020-06-17 04:12:10
问题 How can I stub certain methods (getters, in particular) from Vue single file components for unit testing with mocha/expect? The problem I was facing was the following: I have a component with a get method someData <script lang="ts"> import { Vue, Component } from 'vue-property-decorator' import SomeService from '@/services/some.service' @Component() export default class MyApp extends Vue { ... mounted () { ... } get someData () { return this.$route.path.split('/')[1] || 'main' } get

NODE_ENV with Jest

亡梦爱人 提交于 2020-06-17 02:04:42
问题 I am migrating from Mocha to Jest. My test import the 'config' package, which selects a configuration file or another depending on the NODE_ENV variable. However, it looks like NODE_ENV variable is found by config while running the test from Jest Next line does not work (that is, NODE_ENV is ignored): NODE_ENV=test jest test/*.js --notify --config jest.config.json As a consequence the 'config' package reports: console.error node_modules/config/lib/config.js:1727 WARNING: NODE_ENV value of