Questions tagged [chai]
Chai is a BDD/TDD assertion library for Node.js and browsers that can be used with any Javascript testing framework.
2,869
questions
0
votes
0
answers
16
views
Unit test on API with FileUpload returns (sometimes) ECONNRESET
I'm currently writing an API for my website, and also discovering unit-testing.
I'm using Nodejs with mocha and chai. I've been able to tests on several models, but I'm currently trying to make ...
0
votes
1
answer
16
views
Comparing 2 objects in chai, but checking for its type rather than value
I am trying to assert a response using chai, in such a way that I compare the two objects, instead of asserting each property line by line. I'm not good with words, so here's an example using the ...
0
votes
0
answers
19
views
Partial webelement text selection - WebdriverIO/Mocha/Chai
One of the webelements that I am trying to get the text from has a link/tag as part of that element, that I want to exclude from selecting, but can not figure out how.
This is my code:
await ...
0
votes
0
answers
20
views
How can I test nested slots in Vue
I am trying to pass nested slots into my mounted component and I can;'t figure out the syntax, couldn't find anything in docs.
What I am trying to do is to add html element into drop-down slot
This is ...
0
votes
0
answers
34
views
Typescript TypeORM findOneByOrFail reject returned value
I am writing mocha chai tests with sinon mocking TypeORM repository. My repository has this member:
public async GetByEmail (email: string): Promise<T | null> {
return await this._repository....
0
votes
0
answers
27
views
Solved - Mocha cannot find global types
I wrote small node app with express and made global interface "LocalUser" which is essentially express response but predefined locals. Instead of importing it everywhere, I've decided to ...
0
votes
0
answers
29
views
How to fix a "truffle test" error in Chai [closed]
I'm following a course, and when I do 'truffle test' I get an error, and that is not suppose to happen.
This is my code:
const assert = require('chai')
const KryptoBird = artifacts.require('./...
2
votes
1
answer
27
views
Unit Test with Express / Mocha / Mongodb Memory Server
I would like to configure my project in order to run unit test for some API endpoints (that call the database). I'm using :
ExpressJS
MongoDB (no Mongoose)
Mocha / Chai
Mongodb Memory Server (to mock ...
0
votes
0
answers
19
views
How do I get my mocha/chai test to have arguments refer to the arguments of myFunction and not something else?
I'm trying to test a function with mocha/chai. I'm new to test driven development, so I'm surely referring to a thing or two incorrectly. Feel free to correct me :)
Here's my function:
export const ...
-1
votes
2
answers
37
views
Call smart contract function by connecting contract address in hardhat (ethers)
Background of Problem:
I am developing an NFT Marketplace.
In its workflow, the admin (deployer of the smart contract) adds NFTs to the marketplace, and at that time these NFTs are owned by the ...
0
votes
1
answer
45
views
should.match regex + variable chai expect in single line
import 'mocha';
import * as chai from 'chai';
const should = chai.should();
const expect = chai.expect;
version = "2022-01-30"
let res = "/2022-01-30/images?$top=100&$filter=...
0
votes
1
answer
31
views
Stub promises with sinon
I have a Node js controller that sends an external api which I need to stub using Sinon.
When I mocked the resolve, it went as expected but when I try to mock the reject as well, I get an error which ...
0
votes
1
answer
12
views
How to test next parameter in controller using mocha and chai
I've got a controller which I'm using the 'next' parameter, and I have no idea how to include it into the test. I've done request and response, everything is ok, but when I use the next, I've got the ...
1
vote
2
answers
46
views
How to make sure that a callback has NOT been called?
Let's say I have the following function that periodically checks a condition until it is satisfied.
let loopWithSleep = (callback) => {
if (conds.every(cond => { return cond; })) {
console....
0
votes
0
answers
32
views
Mocha Fails if I change describe text
I am writing some Mocha/Chai tests using the browser version of Mocha. Mocha is failing without any error being thrown in the console if I change any piece of the string argument of a nested describe. ...
0
votes
1
answer
25
views
Chai: Check if any array item is true using 'expect'
I need to check if [boolean,boolean,boolean] array contains only true using specifically expect from chai.
On stackoverflow I found solution with should keyword, but I am only allowed to use expect
...
0
votes
0
answers
25
views
Mocha/Chai/Supertest passing tests when not meeting requirements [duplicate]
I'm currently attempting a technical challenge for an interview in which one I was required to do some testing. I have never TDD/BDD or write any kind of test by myself but I had some... outsided ...
0
votes
2
answers
80
views
How to assert that a JSON contains certain keys?
I have successfully converted an excel sheet's content into a JSON, now I am trying to do some validation to it.
I need to assert that the jsonData below contains the following keys: Breakfast, Lunch, ...
0
votes
0
answers
12
views
How can I add new field in AssertionError stack when using chai.expect
I am using mocha to build and run multiple test at a time, the below function is responsible for the comparing a message doc I have.
const compareTextWithButtonsMessage = (expected, received) => {
...
0
votes
2
answers
29
views
Getting Invalid Chai property: status error which was working fine
would need bit of help. I have written a code for API Test which is below, but I am getting an error Invalid Chai property: status. Can anyone of you please guide what am I doing wrong. This was ...
0
votes
1
answer
9
views
Why does this mocha test timeout when using a simple call with mongoose?
I am trying to make a simple assertion on an async db method:
describe('User Repository', () => {
describe('findById', () => {
it('Returns a user that exists in the db by id', async () =&...
0
votes
1
answer
59
views
before, beforeEach does not execute in hardhat test
This code is for testing a Silent Auction smart contract written in hardhat.
When I type everything separately into the it{...} blocks, the test are passing. When using before, and beforeEach to ...
0
votes
1
answer
16
views
Test assertion inside a hook (Mocha + Chai)
This is my assertion:
it('test 1 - 200', (done) => {
receiver.on("get_payload", (payload) => {
expect(payload).to.be.an("object");
...
0
votes
1
answer
35
views
How to write code for unit testing header in mocha and chai for Node.js express framework application?
I am writing test cases to check with all headers received are correctly spelled or not
suppose there are multiple field names I want to make test cases for all of them that they all are spelled ...
0
votes
0
answers
18
views
Mocha Chai TypeError: Suite argument "title" must be a string. Received type "undefined"
I'm completing the freecodecamp solidity smart contract lottery in js and im trying to run:
npx hardhat test --network rinkeby
but it returns the error
TypeError: Suite argument "title" must ...
0
votes
1
answer
19
views
Chai.Js assertion question/ where can I find resources?
I need to do the two following, where can I begin to start learning?
Write test assertions using Chai.Js that would validate:
200 response code
John Doe exists as an “advisorName” value in the ...
0
votes
0
answers
29
views
Test execution is different between Github Actions and local
I'm testing my express.js API via importing the root app instance and using it through chai-http. The tests are run via mocha.
As the title say, when I run my tests via Github Actions the results are ...
0
votes
1
answer
23
views
Getting undefined response to API Request through Mocha
I am unable to understand that why am I getting the undefined response to my code API request through mocha. Any leads will be appreciated Attaching the codes picture and code itself too.
import ...
0
votes
1
answer
35
views
Mocha after all hook throwing error but functioning correctly - Uncaught Reference error
I am new to testing, and I am using Mocha, Chai and Supertest to write unit tests for my ExpressJS application. My tests are all working - even the hooks that throw errors are functioning as expected, ...
0
votes
0
answers
14
views
Why does chai-http think my response does not exist?
I'm trying to build a backend API of a hypothetical sunglasses website using a TDD methodology with Mocha and Chai. I'm new to it.
When I try to run a test on the following GET request, I get Uncaught ...
0
votes
0
answers
23
views
Chai + WebdriverIO: How to display array contents in expected or actual values?
TL;DR - How can I get wdio + chai to display the contents of a deep actual/expected object? Better yet, how can I get it to show a diff between them?
I've inherited this existing test that is newly ...
0
votes
0
answers
23
views
How to write unit test case using Mocha Chai Sinon of the below scenario?
BankingDocument.findOne({ documentId},
(err, doc) => {
if (err)
throw err;
}
return doc;
}
)
-1
votes
2
answers
60
views
How to test a library in solidity with Chai
What is the best method to test a library contract with Chai/Mocha in solidity using hardhat?
I'm getting:
Types containing (nested) mappings can only be parameters or return
variables of internal or ...
0
votes
2
answers
84
views
How to directly test a Solidity Library with Hardhat/Chai
I'm trying to test a Solidity Library directly using hardhat and chaï.
This is a Library example I would like to test:
library LibTest {
function testFunc() public view returns(bool) {
...
0
votes
0
answers
15
views
How can I do a Mocha nodejs test using stabs and spies instead chai.http?
I have this method in nodejs
save: function(req, res)
{
var params = req.body;
var user = new User();
user.name = params.name;
user.email = params.email;
user.age = params.age;
...
2
votes
1
answer
93
views
Wrong count execution times of Sinon Spy
I have a major function that call 3 other functions. I want to test if those 3 function were called.
myController.ts
import axios from 'axios';
export async function functionOne() {
console.log('...
0
votes
2
answers
35
views
CHAI - See if two objects are the same where one attribute has a different order
I have two object arrays:
array1 = [
{ name: 'Kitty, Hello',
otherNames: [ '(1) One', '(2) Two' ]
},
{ name: 'Cat, Garfield',
otherNames: [ '(3) Three' ]
}
];
array2 = [
{ ...
0
votes
0
answers
15
views
Cannot test addition of object to an array of struct
I am trying to test addition of an object to an array of struct like so:
describe("Create Horse", async function() {
it("horses struct array initialized with 0 horses", ...
0
votes
0
answers
34
views
This driver instance does not have a valid session ID (did you call WebDriver.quit()?)
The problem is I write autotests. Stack: js + chai +mocha+selenium. When running tests using mocha, the first test passes and completes, and the following tests simply do not run. Here is the error ...
-1
votes
1
answer
9
views
Truffle not calling the function in past time
I was writing writing some unit testing code for my vesting smart contract in truffle, when I encountered a problem, I had a function which was getting time as one of its parameters so instead of ...
0
votes
0
answers
19
views
how to Unit test return next() using mocha chai sinon?
I'm writing unit test for the first time. I can't figure out how to test if function returns next(). I have used sinon.spy for next();
I tried checking .should.be.instanceOf('function'), .to.be.a('...
3
votes
1
answer
30
views
Converting should expression to soft assertions
I have a complex form with many individual features to test, and I'd like to traverse the whole page without failing the test. I've seen soft assertions but cannot figure out how to make it work with ...
0
votes
0
answers
10
views
Chai-bignumber not found in npm registry
I have tried setting npm registry using " npm set registry https://npmjs.org/ " but for some reason whenever i try to install chai or chai-bignumber using " npm install chai " or &...
0
votes
0
answers
19
views
Unable to connect to test database when testing api using mocha and chai
I am using mocha and chai to test express api I am trying to test POST request even though it is passed but unable to add the data inside test db.During debugging I got to know that its is unable to ...
0
votes
0
answers
20
views
sinon chai unit test coverage for method call with callback
sinon chai unit test coverage for method call with callback, not getting covered the line,
.on() method with chunk,
async function getOpensearchSignedRequest(apiName, clientKey, fromDate, toDate, ...
0
votes
0
answers
22
views
Solidity: How to test if a function is called from another contract?
I was wondering how I can test if a function is called from another contract using chai.
Contracts will be like:
contract ContractA {
function shouldBeCalledByOthers() { // some code... };
}
...
0
votes
0
answers
13
views
istanbul/nyc + chai Typescript unit tests on static methods
I've a class with a lot of methods, and one of them is static:
export class MyClass() {
static async myFunc(): Promise<Dictionary<string[]>> {
const strings = await new this.Query()....
0
votes
0
answers
59
views
problem in unitest, mocha and chai, React test library
I need to render my pages to do unit tests, but they are causing me a lot of problems
this is page of test
test.tsx
import React, { useState } from 'react';
import {
Button, Checkbox, ...
0
votes
0
answers
11
views
Karma Chai not running some tests
We have this codebase with existing unit tests. When I test just the module I'm adding, all my tests pass. But once I include the tests from the other modules, my tests don't get run anymore. I tried ...
1
vote
0
answers
16
views
Error messages displayed when a test fails using MochaJs
I am using Mocha with chai to perform unit testing. But I can't comprehend the error messages displayed when a test fails.
For instance, I have a simple api, that only accepts alpha characters for ...