chai

“UnhandledPromiseRejectionWarning” error even when catch is present

本小妞迷上赌 提交于 2019-12-07 19:18:48
问题 So I have this code, createExampleDir is not yet implemented, so the test fails: let chai = require('chai'); let expect = chai.expect; let homeDir = require('home-dir'); let lib = require('../lib.js'); chai.use(require('chai-fs')); let dir = homeDir('/example-dir'); describe('lib', () => describe('createExampleDir', () => it('should find ~/example-dir', () => lib.createExampleDir() .then(() => expect(dir).to.be.a.directory()) .catch(() => {throw Error('Who cares!');}) ) ) ); The problem is

How to correctly close express server between tests using mocha and chai

限于喜欢 提交于 2019-12-07 18:42:20
I am looking for a correct way to completely reset my express server between tests! It seems that this is not just a problem for me, many other users have asked the same question, and many blog posts had been written on the argument. The proposed solutions are not working nor satisfactory for me. Here there is another similar question and an article that well describes the problem and suggests some solutions: Stack overflow Closing an express server after running jasmine specs Blog: https://glebbahmutov.com/blog/how-to-correctly-unit-test-express-server/ Here a package is specifically created

How to sinon spy module export utility functions

与世无争的帅哥 提交于 2019-12-07 15:06:53
问题 In javascript (ES6), I have a utility module which just contains some functions, and then in the end of the file, I export them like so: module.exports = { someFunction1, someFunction2, someFunction3, } Then I want to write unit tests for those functions. Some of the functions depend on each other; they call each other in a way, that for example, someFunction1 might call someFunction2. There's no circular problems. Everything works well, until I need to spy that one of the functions is called

Why is my mocha/chai Error throwing test failing?

爱⌒轻易说出口 提交于 2019-12-07 03:12:06
问题 I have a simple javascript package I'm trying to test. I want to check for an Error being thrown, but when my test is run, and the error is thrown, the test is marked as failing. Here's the code: var should = require('chai').should(), expect = require('chai').expect(); describe('#myTestSuite', function () { it ('should check for TypeErrors', function () { // Pulled straight from the 'throw' section of // http://chaijs.com/api/bdd/ var err = new ReferenceError('This is a bad function.'); var

Mocha-Chai throws “navigator not defined” due to React-router component

一个人想着一个人 提交于 2019-12-06 23:19:06
问题 I am writing a test for a React component that uses react-router. I am using Mocha with Chai and Chai-jQuery. My tests work fine, until I import a component from react-router into a component (e.g. Link). At this point, I get the following error: ReferenceError: navigator is not defined at Object.supportsHistory (/Users/nico/google-drive/code/agathos/client/node_modules/history/lib/DOMUtils.js:61:12) I used to get a similar error with react-bootstrap until I updated to react-bootstrap v0.29.3

Assert that element is not actionable in Cypress

夙愿已清 提交于 2019-12-06 19:24:02
问题 If an element is not actionable on the page (in this case, covered by another element) and you try to click it, Cypress will show an error like this: CypressError: Timed out retrying: cy.click() failed because this element: <span>...</span> is being covered by another element: Great! But is there any way to assert that this is the case, aka that the element cannot be clicked? This doesn't work: should.not.exist - the element does exist should.be.disabled - the element is not disabled should

Error: [$injector:unpr] Unknown provider: $stateProvider <- $state

寵の児 提交于 2019-12-06 18:09:52
问题 Executing below unit test gives "Error: [$injector:unpr] Unknown provider: $stateProvider <- $state". I have attached the angular-ui-router.min.js in karma file. describe("Unit tests", function() { var $rootScope, $injector, $state; console.log("hello"); beforeEach(inject(function(_$rootScope_, _$state_, _$injector_, $templateCache) { console.log("hello1"); $rootScope = _$rootScope_; $injector = _$injector_; $state = _$state_; })); describe("states", function() { it("verify state

Node Module Export Returning Undefined

╄→尐↘猪︶ㄣ 提交于 2019-12-06 16:38:26
I am trying to create a node module to grab some posts but I am getting an undefined error. Index.js var request = require('request'); function getPosts() { var options = { url: 'https://myapi.com/posts.json', headers: { 'User-Agent': 'request' } }; function callback(error, response, body) { if (!error && response.statusCode == 200) { return JSON.parse(body); } } request(options, callback); } exports.posts = getPosts; test/index.js var should = require('chai').should(), myModule = require('../index'); describe('Posts call', function () { it('should return posts', function () { myModule.posts()

AssertionError: expected [ true ] to be true

邮差的信 提交于 2019-12-06 10:22:39
I have faced with the strange assertions problem so even successful assertions are marked as failed, like this: this.expect(this.getWidget('contacts').isNamesDisplayed()).to.eventually.be.true.and.notify(next); and in the console I have: 1 scenario (1 passed) 4 steps (4 passed) 0m03.618s [17:06:38] E/launcher - expected [ true ] to be true [17:06:38] E/launcher - AssertionError: expected [ true ] to be true As you see in this case test marked as successful despite of failed assertion, but in case when after 'failed' assertion there is another one the whole thing will be failed. I'm using the

How to test John papa vm.model controllers and factories unit testing with jasmine?

你。 提交于 2019-12-06 09:40:30
Ive been using John Papa's style guide for my angular apps and Im just starting to get into the testing. However I can't seem to find any good documentation regarding testing the style with mocha, chai, and jasmine. Here is an example of one of my controllers (function () { 'use strict'; angular.module('app').controller('appController', appControllerFunction); function appControllerFunction($scope, $rootScope, $location, dataService, dataFactory) { var vm = this; function getData() { vm.data = dataService.returnData().then(function(data){ ... //http service returning data }); ... } getData();