should.js

How to check for class inheritance in Coffeescript Mocha Test?

倾然丶 夕夏残阳落幕 提交于 2020-03-25 18:54:18
问题 How do I check for the class of an object in a mocha spec in Coffeescript? I have tried the following: # foo.coffee class Foo module.exports = new Foo() # foo_spec.coffee should = require 'should' { Foo } = require 'foo' foo = new Foo foo.should.be.an.instanceOf(Foo) However, I receive ReferenceError Foo is not defined 回答1: I believe this to be the easiest approach: # foo.coffee class Foo module.exports = new Foo() module.exports.Foo = Foo # IMPORTANT, exports the actual class Foo # foo_spec

Mocha async test handle errors

断了今生、忘了曾经 提交于 2020-01-02 19:34:22
问题 I'm trying to create a test case with Mocha but my code is asynchronous. That's fine, I can add a "done" callback function to "it" and that will work perfectly fine for positive cases. But when trying to test negative cases, it will just make the test fail. I would like to make something like this but asynchronous: someObject.someMethod(null).should.equal(false) Instead I can only test for a callback to return, instead of testing what really happend (null is not valid): it('this should return

Mocha async test handle errors

≡放荡痞女 提交于 2020-01-02 19:34:08
问题 I'm trying to create a test case with Mocha but my code is asynchronous. That's fine, I can add a "done" callback function to "it" and that will work perfectly fine for positive cases. But when trying to test negative cases, it will just make the test fail. I would like to make something like this but asynchronous: someObject.someMethod(null).should.equal(false) Instead I can only test for a callback to return, instead of testing what really happend (null is not valid): it('this should return

Should js Cannot read property 'should' of null

六眼飞鱼酱① 提交于 2019-12-21 03:23:13
问题 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

Asserting files that have the same content

≯℡__Kan透↙ 提交于 2019-12-20 19:05:29
问题 I am using mocha/supertest/should.js to test my Rest Service GET /files/<hash> returns file as stream. How can I assert in should.js that file contents are the same? it('should return file as stream', function (done) { var writeStream = fs.createWriteStream('test/fixtures/tmp.json'); var req = api.get('/files/676dfg1430af3595'); req.on('end', function(){ var tmpBuf = fs.readFileSync('test/fixtures/tmp.json'); var testBuf = fs.readFileSync('test/fixtures/test.json'); // How to assert with

Chai, Mocha: Identify should assertion

£可爱£侵袭症+ 提交于 2019-12-13 13:10:21
问题 I'm using mocha and chai as assertions. I have several assertions in my spec: Exp1.should.be.true Exp2.should.be.true Exp3.should.be.true If one of them fails mocha writes "expected false to be true". Is there a way to identify them? With expect I can do it: expect(Exp1, 'Exp1').to.be true Is something like this possible with should ? 回答1: Apparently should does not support custom error messages at the moment. You can create your own helper for setting the message: var chai = require('chai'),

How to start Locomotive server/app for integration testing?

我与影子孤独终老i 提交于 2019-12-13 07:23:27
问题 I am converting an Express app to Locomotive and I cannot figure out how to migrate my tests. In Express, I simply did this in my /test/test.api.organization.js file: var app = require("../app").app, request = require("supertest"); should = require("should"); describe("Organization API", function() { it( "GET /api/v1/organizations should return status 200 and Content-Type: application/json.", function (done) { postReq.done( function () { request(app) .get( "/api/v1/organizations" ) .set(

How would Object.defineProperty be in AS3?

走远了吗. 提交于 2019-12-11 11:43:20
问题 I'm an architect from a strong JavaScript background, but I did some .NET and Java in the past. However, I wanted to put a hand on ActionScript3, which I was promised that is very related to JavaScript. As a startup project I took on myself to try port to ActionScript3 one of my favorite assertion utils - should.js - that makes your test codes really pleasant to read. Updated: 2013-02-19 I saw I confuse with my abstract speaking, so I replaced some of the post with the concrete question in

Object #<Object> has no method 'type'

笑着哭i 提交于 2019-12-11 05:46:13
问题 My test code is var strategy = require('../lib'); var should = require("should"); describe('passport-twitter', function() { it('should export Strategy constructor directly from package', function() { console.log('strategy is',strategy); strategy.should.have.type('function'); }); it('should export Strategy constructor', function() { strategy.Strategy.should.have.type('function'); }); }); and when i run this test.it is giving me error 1) passport-twitter should export Strategy constructor

Why is typescript compiler omitting 'should.js' import in generated javascript?

允我心安 提交于 2019-12-11 00:11:21
问题 I am facing a weird issue. In my (lets say) a.ts I have - /// <reference path="../typings/mocha/mocha.d.ts" /> /// <reference path="../typings/should/should.d.ts" /> import should = require('should'); import something_else = require('../something-else'); Now when I compile using command - tsc -m commonjs --outDir "./build" "src/test/a.ts" My generated javascript is not having require for should - /// <reference path="../typings/mocha/mocha.d.ts" /> /// <reference path="../typings/should