Questions tagged [chai]

Chai is a BDD/TDD assertion library for Node.js and browsers that can be used with any Javascript testing framework.

Chai is a / assertion library for and that can be used with any testing framework.

2953 questions
1
vote
1 answer

Chai exports are not found in Mocha test

I have created simple Mocha test. It works perfectly when Node "assert" module is used. I run it from command line (Mocha is installed as a global node module): $ mocha myTest.js ․ 1 test complete (6 ms) The script looks like this: var assert =…
Pavel S.
  • 11,892
  • 18
  • 75
  • 113
1
vote
1 answer

jsdom and script tags with relative paths

I have some single page demos like this one here: http://notjs.org/examples/forms/formmode_demo.html I thought, wow, it would be super awesome if could write some tests in my existing mocha chai badness setup to test the examples directly like so: …
Bee Wilkerson
  • 93
  • 2
  • 9
0
votes
2 answers

Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised

I have a test that works on webdriverio, but when I move the browser into a class this error comes out: Unable to load spec files quite likely because they rely on `browser` object that is not fully initialised. The class: /* eslint-disable…
0
votes
0 answers

Mock node-mssql package with sinon

In my app I have a process that involves CRUD operations on a mssql database. For the connection to the db I'm using node-mssql and for establishing the connection itself I'm basically following the official documentation at…
TheDude
  • 1,205
  • 2
  • 13
  • 21
0
votes
1 answer

Cypress soft assertions with cy.origin - Why is it passing a test with failed assertions?

I think we all know that cypress and soft assertions has been discussed to death, and various solutions to implementing soft solutions are out there. For some time now, I've been using the following code, based on the old stack question Does cypress…
Steve H
  • 280
  • 1
  • 2
  • 11
0
votes
0 answers

How to write unit test cases for kafkajs consumer and producer

I'm new to kafkajs and I want to write unit test cases for the Kafka consumer and producer. Currently my project uses Typescript, Chai and Mocha as test framework.
Kiran
  • 23
  • 4
0
votes
1 answer

How to use expect in playwright js?

I have following code written in puppeteer with chai. How could it be written in playwright js? const expect = require("chai").expect; const puppeteer = require("puppeteer"); (async () => { const browser = await puppeteer.launch({ headless:…
user1953051
  • 321
  • 2
  • 7
  • 21
0
votes
1 answer

I can't use third party assertions like it fit describe fdescribe on Testcafe

I would like to run tests from another fixtures using assertions like: .describe .it .fit .test, etc I already import the Testcafe module: import { testcafe} from 'testcafe'; Or import { t, Selector, describe} from 'testcafe'; And I tried many…
0
votes
0 answers

Sinon Fake called Not True

Why is errorFake not being called when I call visually see it's being called (i.e., the message 'message' is logged in the logs ([routes/events] 04:06:16 PM error: message)? Code to test const { scopedLogger } = require(); const…
0
votes
1 answer

How to test the revert for 'call' function with Hardhat?

I would like to have 100% code coverage but one function is giving trouble ... (bool sent, bytes memory data) = _to.call{value: msg.value}(""); require(sent, "Failed to send Ether"); How to force the boolean 'sent' to false ? Stack : hardhat,…
MiKa
  • 15
  • 3
0
votes
0 answers

Running multiple test files with chai where all of them use mongoDB memory server returns error

So I want to test my integration with mongodb-memory-server. I created two seperate test files for different use cases, and both connect and disconnect to mongodb in before and after functions. This is my db.js file, where I have my connect and…
mehawelm11
  • 15
  • 5
0
votes
0 answers

combine all the stubs for methods in one file and then importing it?

i am writing unit test cases and i want to write all my stubs in one file and then import it whenever my unit test case require the stub .
riti
  • 1
  • 1
0
votes
0 answers

How to mock middleware authentication for unit test? Mocha, Chai and Sinon

I have the following route: router.post('/price-request/create', auth.middleware('jwt'), (req, res) => priceRequestController.create(req, res) ); I need to test the controller, the controller has the following: async create(req: Request, res:…
0
votes
0 answers

How does Chai make terminating parenthesis with arguments optional?

This is closely related to How does Chai JS make function parentheses optional?, but not quite identical. Make the parentheses in function calls optional also seems similar, but the second link isn't using Object.defineProperty and the first link…
user3534080
  • 1,201
  • 1
  • 14
  • 21
0
votes
0 answers

How can I access the req object in Chai

I am learning to use Chai and Mocha to create unit tests. Right now I am having a heck of a time figuring out how to access the req object. I have seen in multiple places in the documentation that you can use expect(req) in multiple ways, but it…
Brenden
  • 60
  • 7
1 2 3
99
100