chai

How can I get Chai to show actual and expected values using toString()

偶尔善良 提交于 2019-12-10 16:17:20
问题 I recently switched from should.js to chai.js, as I discovered the former was causing snags in browser-based testing. The change didn't require any changes to my test suite, as the syntax is supported, but I see that the output of failing tests no longer shows me the actual and expected values in a useful way: AssertionError: expected [ Array(9) ] to deeply equal [ Array(9) ] I can get it to spit out a representation of these values by adding this line: chai.config.truncateThreshold = 0;

How to post an array of objects with Chai Http

筅森魡賤 提交于 2019-12-10 15:57:59
问题 I'm trying to post an array of object with ChaiHttp like this: agent.post('route/to/api') .send( locations: [{lat: lat1, lon: lon1}, {lat: lat2, lon: lon2}]) .end (err, res) -> console.log err, res It returns an error as below: TypeError: first argument must be a string or Buffer at ClientRequest.OutgoingMessage.end (_http_outgoing.js:524:11) at Test.Request.end (node_modules/superagent/lib/node/index.js:1020:9) at node_modules/chai-http/lib/request.js:251:12 at Test.then (node_modules/chai

NightmareJS multiple evaluations

谁说我不能喝 提交于 2019-12-09 18:06:35
问题 NightmareJS works great when I am running one evaluation, but as I interact with the page I need to do more evaluations as things pass. However using the docs I tried a simple sample of chaining evaluations and I get an error: describe('test google search results', function() { this.timeout(15000); it('should find the nightmare github link first', function(done) { var nightmare = Nightmare({show: true}) nightmare .goto('http://google.com') .wait(1000) .type('form[action*="/search"] [name=q]',

How to create Firebase token on server for use with unit tests?

末鹿安然 提交于 2019-12-08 17:15:35
问题 I need to authenticate a Firebase user using node so I can test some server side methods. For each protected request, I verify the Firebase token using: firebase.auth().verifyIdToken(firebaseAccessToken).then(function(decodedToken) { // forward request }) So in my test I created a token with a uid from my Firebase database firebase.auth().createCustomToken(uid).then(function(token) { //add to header for requests }) Later I read that custom tokens are not verified by the verifyIdToken method,

How do I test if a function calls a specific method/function?

拈花ヽ惹草 提交于 2019-12-08 14:43:56
问题 Is there a way in Mocha to test if a function calls a specific method or external function? I am using Mocha with Chai, but am open to any other assertion libraries. Ok, so testing whether a methid is being called is pretty easy using sinon. I'm not sure about testing to see if an external function is being called though. So I updated the examples to represent something a little more "real world". I am working on a node app, so foo.js and bar.js are both modules. Example: foo.js var bar =

How to make Istanbul generate coverage for all of my source code?

坚强是说给别人听的谎言 提交于 2019-12-08 14:37:50
问题 Currently Istanbul is only generating coverage for files that are used in my tests, which is okay, but seems to defeat the purpose of having coverage somewhat. I have no Istanbul configuration, and am invoking it via npm test with the following script string: $ istanbul cover _mocha -- -R dot --check-leaks --recursive test/ Is there a way to generate coverage for all of my source code? 回答1: Found the answer, I think I'm partly lucky that the directory structure I have chosen allows me to use

All steps shown as pass before protractor cucumber execution

江枫思渺然 提交于 2019-12-08 12:59:38
问题 While executing my scripts, Immediately all steps shows as pass in console after that my actual scripts getting executed. Even after returning promise in each step. Feature File: Feature: Running Cucumber with Protractor Scenario: To verify the Search result Given I am on home page When I enter search value Then I verify the search page Step Definition: var chai = require('chai'); var chaiAsPromised = require('chai-as-promised'); var expect = chai.expect; chai.use(chaiAsPromised); module

Node Module Export Returning Undefined

一世执手 提交于 2019-12-08 08:32:47
问题 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('..

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

非 Y 不嫁゛ 提交于 2019-12-08 03:11:37
问题 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:/