should.js

Catching thrown errors with SinonJS

你离开我真会死。 提交于 2019-12-10 09:47:35
问题 I've got a method that may throw an Error, but I'm having trouble writing a SinonJS/Mocha/Should unit test case for this condition. Sample function under test: function testError(value) { if (!value) { throw new Error('No value'); return false; } }; Sample test: describe('#testError', function() { it('throws an error', function() { var spy = sinon.spy(testError); testError(false); spy.threw().should.be.true(); }); }); This outputs: #testError 1) throws an error 0 passing (11ms) 1 failing 1)

Test custom method on React component has been called, using Enzyme and Sinon

只愿长相守 提交于 2019-12-07 07:24:02
问题 I want to check that when a button is clicked on my component, it calls the method I have created to handle the click. Here is my component: import React, { PropTypes, Component } from 'react'; class Search extends Component { constructor(){ super(); this.state = { inputValue: '' }; } handleChange = (e) => { this.setState({ inputValue: e.target.value }); } handleSubmit = (e) => { e.preventDefault(); return this.state.inputValue; } getValue = () => { return this.state.inputValue; } render(){

Catching thrown errors with SinonJS

拜拜、爱过 提交于 2019-12-05 21:41:12
I've got a method that may throw an Error, but I'm having trouble writing a SinonJS/Mocha/Should unit test case for this condition. Sample function under test: function testError(value) { if (!value) { throw new Error('No value'); return false; } }; Sample test: describe('#testError', function() { it('throws an error', function() { var spy = sinon.spy(testError); testError(false); spy.threw().should.be.true(); }); }); This outputs: #testError 1) throws an error 0 passing (11ms) 1 failing 1) #testError throws an error: Error: No value at testError (tests/unit/js/test-error.js:6:14) at Context.

Where should unit tests be placed in Meteor?

眉间皱痕 提交于 2019-12-04 07:58:12
问题 Is there a place where my tests can live without being run by Meteor? I just started my first Meteor project, and began by writing unit tests with Mocha and should.js. Though mocha runs without a problem, the tests prevent Meteor from starting up since it has issues using node's require instead of __meteor_bootstrap__.require (full error message). That being said, Meteor should not be running my tests! According to the Meteor documentation, code can only be placed on the client, server, or

Should js Cannot read property 'should' of null

独自空忆成欢 提交于 2019-12-03 09:25:56
i try to use the testing tool mocha in node. Consider the following test scenario var requirejs = require('requirejs'); requirejs.config({ //Pass the top-level main.js/index.js require //function to requirejs so that node modules //are loaded relative to the top-level JS file. nodeRequire: require }); describe('Testing controller', function () { it('Should be pass', function (done) { (4).should.equal(4); done(); }); it('Should avoid name king', function (done) { requirejs(['../server/libs/validate_name'], function (validateName) { var err_test, accountExists_test, notAllow_test, available_test