Questions tagged [expect.js]

Expect.js is a library of Javascript which is minimalistic BDD assertion toolkit based on should.js .

Expect.js is a library of Javascript which is minimalistic BDD assertion toolkit based on should.js .

Features:

  • Cross-browser: works on IE6+, Firefox, Safari, Chrome, Opera.
  • Compatible with all test frameworks.
  • Node.JS ready (require('expect.js')).
  • Standalone. Single global with no prototype extensions or shims.

Here is github library of expect.js.

17 questions
84
votes
5 answers

Re-throwing exception in NodeJS and not losing stack trace

How can I rethrow an error or exception in nodejs/javascript and include a custom message. I have the following code var json = JSON.parse(result); and I wanted to include the result content in the exception message should any parsing error occurs.…
alayor
  • 4,537
  • 6
  • 27
  • 47
13
votes
2 answers

Test with reactjs renderIntoDocument keep failed due to required DOM

I am new to reactJS and try to learn how to test with it. I have encouter the following testing util method. However i am keep getting the same error message:ReferenceError: document is not defined. renderIntoDocument ReactComponent…
Bill
  • 17,872
  • 19
  • 83
  • 131
9
votes
1 answer

Testing Redux combined reducers

Say I have several reducer functions and I combine them all into one reducer using combineReducers(...), is there a way of testing what reducers the combined reducer actually contains? For example, if I have this: import { combineReducers } from…
Dylan Parry
  • 3,373
  • 6
  • 26
  • 38
7
votes
1 answer

Mocha Test: Uncaught TypeError: Cannot read property 'status' of null

Learning TDD and my first simple test for my "Hello World" server response is failing in Mocha. I'm using Mocha.js, Superagent, & Expect.js. When I curl -i localhost:8080, I get the correct response and status code. HTTP/1.1 200 OK Content-Type:…
metame
  • 2,480
  • 1
  • 17
  • 22
5
votes
2 answers

Where is AssertionError defined in Node.js?

I'd like to have my unit tests assert that a particular function call throws an AssertionError specifically when expected, rather than that it throws an exception at all. The assertion library (expect) supports such a thing by passing an exception…
Turner Hayes
  • 1,844
  • 4
  • 24
  • 38
3
votes
1 answer

Expect.js validation issue on Codeacademy Lesson

I am creating a lesson on codeacademy that enables users to learn about the creation of HTML forms. This is mostly for my own entertainment, just so we're all on the same page. After reading the submission test guidelines and API I decided to use…
djthoms
  • 3,026
  • 2
  • 31
  • 56
2
votes
3 answers

How to Assert from multiple possibilities in Cypress? One option could be true out of multiple

I have a scenario, where i need to put Assertion on an element's text which could be true OR pass the test case, if the any 1 value is present out of many. Let say, an element can contain multiple status' : 'Open', 'Create', 'In Progress' any of…
Amit Verma
  • 109
  • 7
2
votes
1 answer

How to sinon spy a React component constructor - unit testing?

I'm using enzyme, sinon and expect to unit test my react component. import React from 'react'; import expect from 'expect.js'; import { shallow } from 'enzyme'; import ExampleComponent from…
user1261710
  • 2,539
  • 5
  • 41
  • 72
1
vote
1 answer

jest.fn() not recognized by expect as a spy function?

Error: The "actual" argument in expect(actual).toHaveBeenCalled() must be a spy Minimal not-working example: const mockFn = jest.fn(); mockFn(); expect(mockFn).toHaveBeenCalled(); Question: is jest.fn() not a spy?
CherryQu
  • 3,343
  • 9
  • 40
  • 65
1
vote
2 answers

Webpack Breaks Mocha in Node.js App

I have a node.js app that uses Mocha and Expect for testing. All the tests work great, until I installed webpack for react. Now when I run "npm test" I get the following error: Error: Cannot find module 'should' at…
1
vote
1 answer

Testing an extension to expect.js

I'm writing some expect.js matchers and I'd like to test the matchers themselves. So I want to write positive and negative tests. Let's say I've written toContainItem(name); used like this; expect(femaleNames).toContainItem('Brad'); // test…
Steve Cooper
  • 20,542
  • 15
  • 71
  • 88
0
votes
3 answers

How do I get a meaningful test error when assertion is in a promise?

I'm having a hard time getting meaningful failures in tests when I need to check things in a promise. That's because most testing frameworks use throw when an assertion fails, but those are absorbed by the then of promises... For example, in the…
Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
0
votes
1 answer

expect (js) not working inside superagent (js)

I'm trying to do TDD for the Rest APIs that I've been creating. New to NodeJS. I've created a Rest API, and on the response I want to perform all the expect checks. To make an HTTP request I'm using SuperagentJS (also tried RequestJS). Here is how…
Ashwani Agarwal
  • 1,279
  • 9
  • 30
0
votes
2 answers

Testing Node.js api with mocha

I am busy building functional tests for an existing nodejs api I wrote. I am using mocha and expect.js. One test that is failing is when I want to do a negative test for the existence of a url parameter. What I want is to send a message back to the…
Ebbs
  • 1,030
  • 3
  • 20
  • 38
0
votes
2 answers

Testing, do I need to add more Return statements to my functions?

I would like to start using a test framework, mocha + expect seem good to me. Say i have this function, /* * Hides or shows loading .gif * show : boolean */ function loadingMsg(show) { var $loader = $("#loader"); if(show){ …
rssfrncs
  • 991
  • 4
  • 19
1
2