by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 05 01:07

    chaijs-bot on master

    (data): Auto build _data (compare)

  • Aug 04 23:10
    leonleo997 commented #887
  • Aug 03 01:06

    chaijs-bot on master

    (data): Auto build _data (compare)

  • Jul 30 12:13
    regaldisclaimer closed #274
  • Jul 30 12:13
    regaldisclaimer commented #274
  • Jul 30 12:00
    austince commented #274
  • Jul 30 08:37
    regaldisclaimer opened #274
  • Jul 30 01:27
    Craigfis opened #273
  • Jul 29 10:24
    ThisIsMissEm commented #1356
  • Jul 29 09:13
    keithamus closed #1356
  • Jul 29 09:13
    keithamus commented #1356
  • Jul 28 21:14
    ThisIsMissEm opened #1356
  • Jul 27 22:57
    LEQADA edited #183
  • Jul 25 01:01

    chaijs-bot on master

    (data): Auto build _data (compare)

  • Jul 23 13:21
    R1Daneel commented #1203
  • Jul 23 01:01

    chaijs-bot on master

    (data): Auto build _data (compare)

  • Jul 19 00:58

    chaijs-bot on master

    (data): Auto build _data (compare)

  • Jul 17 14:02
    DanielVenturini review_requested #1355
  • Jul 17 14:02
    DanielVenturini opened #1355
  • Jul 17 00:58

    chaijs-bot on master

    (data): Auto build _data (compare)

Yaser Moradi
@ysmoradi
Interesting repo => Mocha + TypeScript + Chai
https://github.com/ysmoradi/mocha-chai-ts-starter
Jacopo
@JacopoBonta_gitlab
Hi all, i'm trying to test a node.js class that extends EventEmitter but the test returns ok even before the event is fired. Why this happen? Maybe there is a proper way to test data emitted by events.
Here is the test code, basically it have to validate a json emitted on the tick event.
const chai = require('chai')
chai.use(require('chai-json-schema'))

const { expect } = chai

const RideSimulator = require('../src/RideSimulator')

describe('RideSimulator run()', () => {
    it('should return a json compliant to the schema', () => {

        let schema = { ... schema omitted ... }

        let ride = new RideSimulator(1, 1)

        ride.on('tick', (busData) => {
            expect(busData).to.be.jsonSchema(schema)
        })
    })
})
Jacopo
@JacopoBonta_gitlab
I found a solution here https://stackoverflow.com/questions/16826352/whats-the-best-way-to-unit-test-an-event-being-emitted-in-nodejs
walternolak
@walternolak
Hello! I’m trying to use chainable getter AND. Not sure if this syntax is correct: expect(someCondition).to.be.true.and.expect(otherCondition).to.be.false
If not what would be the correct one using AND
Thanks in advance!!
Kwirke
@kwirke
Hi @walternolak ,
When you concatenate assertions with .and, you are still referring to the same test subject, so you can't chain another expect. Instead, do a new line and have two separate assertions beginning with expect()
Bonus points if you make it as two different tests (it block) because that's a recommended good practice for clarity: One assertion per test
walternolak
@walternolak
@kwirke Understood! thanks for your response.
philicia
@tirzahtoh_twitter
Hi how do I use chai to compare with the expected nested json such as this: const expectedJson = { "authToken": "eyJraWQiOiJVdEI4c0hhYnk0aXBLNlwvQTZnaHBkRFFqRU9tdlptSnZZQTJpNFwvM2w3UmM9IiwiYWxnIjoiUlMyNTYifQ.eyJzdWIiOiIyMTVhMGVhZS00ZjkwLTRlODItOWY4Zi1lNzhlOTdkMzcyODAiLCJldmVudF9pZCI6ImVkNGY5MDJmLTFhM2UtNDRkYy1hNjg2LWY3ZjVjZDM3ODA5OCIsInRva2VuX3VzZSI6ImFjY2VzcyIsInNjb3BlIjoiYXdzLmNvZ25pdG8uc2lnbmluLnVzZXIuYWRtaW4iLCJhdXRoX3RpbWUiOjE1NjUwOTk1OTAsImlzcyI6Imh0dHBzOlwvXC9jb2duaXRvLWlkcC51cy1lYXN0LTIuYW1hem9uYXdzLmNvbVwvdXMtZWFzdC0yX2EzbE5SRU5QMSIsImV4cCI6MTU2NTEwMzE5MCwiaWF0IjoxNTY1MDk5NTkxLCJqdGkiOiJkMjY4YjRkMi01ZWVhLTQ4OGItODUyZi1lNGM4MWRmMWFiYzMiLCJjbGllbnRfaWQiOiI2Z2xwbmRxb2s2YWhua3M2dGFnNXQ5cGMwZyIsInVzZXJuYW1lIjoicWFAdGVsZXBhdGh5LmFpIn0.UlN9bucJbjS4nT8Ly0m9zKRctkyLp9hyIVt9v2l4GdyYptOAvPC3nJl3NrVJGRICAVXRZgswWqCDfifxYUaQ64XGNCrCkLMQ9ecgsNK5ZMuFl7ebl5m1bs3FZTyD-c2fAlzRlAGlLe5ADFN-IPBDI_lmkqd3bhA9wxPrPR7uc7HOl_rjUgsqDd0saO0OPw4AmGpuSqeT56XHoc_IuPUwk6KdPEJ4kO5pIz0hw__QNspMBsoOUrH1pt4TYD9dYTMyrFGJNhPDElJBrxFpGR1TIO7eiXAc_-8z-dhEY4Ek8fyPK8ULqEyk-0UD7QgXCe6TgqdD5jBVTB3aHTYpzn2gLg", "clientInfo": { "clientId": "0d6fc71d-46ff-4441-904f-9f5fd36a43a2" } }
Isabel Giang
@hollowsunsets
hello, I'm trying to test some asynchronous functions to see if they throw errors when expected
i've read that you no longer need chai-as-promised to do this
do you know what exactly I'd need to change? this is what I have right now and i'm not sure if it's correct syntactically
await expect(object.classMethod()).to.eventually.be.rejectedWith(TypeError, "errorMessage");
Dan Čermák
@dcermak
Is there a simple way how I can make a plugin "return a value" from an assertion chain?
for example, let's say I have this chain ctx.should.do.foo(barFuncThatReturnsSmth) and I'd like this chain to return the return value of barFuncThatReturnsSmth
I have tried to override this._obj in the definition of the method foo, but that didn't work. The object is there, but is not returned directly (it's hidden inside some __flags object)
DJ Tinkers
@TinkersDj_twitter

Anyone interested in an opensource project?

Spec oriented development speeds up programming by generating code based on tests/specs. Tests required will be the same or less specs as a normal developer writes.

https://github.com/Neur0plasticity/spec-dev

MSG me if interested

Sven Murat
@sven14_gitlab

is it possible to pass true or false as argument, e.g.

    expect(
      selector.isEnabled(),
      "msg",
    ).to.be.(Enabled)

where Enabled is true or false?

Eric Eastwood
@MadLittleMods
@sven14_gitlab Yes, you can use expect(selector.isEnabled()).to.be.(true)
aeutalt
@aeutalt
how can i verify if an element is visible and then store it in a variable?
trying to do it like this: let = expect.to.be.Visible("myElementId");
Eric Eastwood
@MadLittleMods

@aeutalt You could add your own matcher method, https://www.chaijs.com/api/plugins/#addmethodctx-name-method

But I suspect there is some assertion library that someone has made for working with elements already that you could install

aeutalt
@aeutalt

it('if test case', async function () {

    var cardProcZero = await driver.hasElementByAccessibilityId("card_proc_0"); // looks up the element

    var visivel = expect(cardProcZero).to.exist; // expects it to exist 

    if (cardProcZero == visivel) { // if it is visible, it clicks on it
        it('test case 1', async function () {
            await cardProcZero.click();
            return true;
        });
    } else {
        it('test case 2', async function () { // if it's not visible, it creates the element
            let adicionarProc = await driver.waitForElementByAccessibilityId("button_addProcedimento");
            await adicionarProc.click();
            return false;
        })
    }
});

});
``

@MadLittleMods i'm trying to do it like that
but the test always passes for some reason
is something wrong with my logic/code?
Eric Eastwood
@MadLittleMods
@aeutalt Returning a boolean won't fail a test. You should use someting like expect.ok() and expect.fail();
aeutalt
@aeutalt
tried var visivel = expect(cardProcZero).to.not.be.ok;
all tests passed
but the if else didn't do anything
alefuedev
@alefuedev
Hi there I trying to test my app but my test get stock on the first test if I do one at the time works correctly I hope someone can point me in the right direction

``` var chaiHttp = require("chai-http");
var chai = require("chai");
var assert = chai.assert;
var server = require("../server");

chai.use(chaiHttp);

suite("Functional Tests", function() {
test("POST =>Create a thread", function(done) {
chai.request(server)
.post("/api/threads/:board")
.type("form")
.send({
board: "test",
text: "Testing post request with Chai",
delete_password: "deleteChai!1234"
})
.end(function(err, res) {
chai.assert(res.status, 200);
chai.assert(
res.redirects[0].split("/").length - 1,
"test"
);
done();
});
});

test("GET =>Get threads", function(done) {
    chai.request(server)
        .get("/api/threads/test")
        .end(function(err, res) {
            chai.assert(res.body[0]["board"], "test");
            chai.assert(
                res.body[0]["text"],
                "Testing post request with Chai"
            );
            done();
        });
});

});```

var chaiHttp = require("chai-http");
var chai = require("chai");
var assert = chai.assert;
var server = require("../server");

chai.use(chaiHttp);

suite("Functional Tests", function() {
    test("POST =>Create a thread", function(done) {
        chai.request(server)
            .post("/api/threads/:board")
            .type("form")
            .send({
                board: "test",
                text: "Testing post request with Chai",
                delete_password: "deleteChai!1234"
            })
            .end(function(err, res) {
                chai.assert(res.status, 200);
                chai.assert(
                    res.redirects[0].split("/").length - 1,
                    "test"
                );
                done();
            });
    });

    test("GET =>Get threads", function(done) {
        chai.request(server)
            .get("/api/threads/test")
            .end(function(err, res) {
                chai.assert(res.body[0]["board"], "test");
                chai.assert(
                    res.body[0]["text"],
                    "Testing post request with Chai"
                );
                done();
            });
    });
});
Sreenivasulu Bellamkonda
@sreeni1990
Hi All, I need use this chai js in plain java script(ECMAScript Engine ) for assert the request and response from API, i will use browser only to run this script ..
Without node js ...i want import this chai js in my java script file and want to use it ..Could you please suggest me how could i do the same
Eric Eastwood
@MadLittleMods
Sreenivasulu Bellamkonda
@sreeni1990
Thank you Eric..
Can i use the Chai js alone in java script/ES6 files for request and response validation /assertion
without using mocha and nodejs
Sreeni Bellamkonda
@SreeniBellamko1_twitter
@MadLittleMods ,
I am trying to assert the property which is not found in chai js
Eg : expect(false).to.not.be.test
test is not found in chai js library
if I run through browser it is throwing an error , But i if run through ECMAScript engine /Rhino engine it not through any error
here is the code :
Sreeni Bellamkonda
@SreeniBellamko1_twitter

import java.io.*;
import java.util.stream.IntStream;

import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;

public class EcmaScriptTest {
public static void main(String[] args) throws Exception {

    // Creating Rhino engine
    Context context = Context.enter();
    Scriptable globalScope = context.initStandardObjects();

    //loading chai js lib
    String[] jsFiles = { "chai.js" };
    IntStream.range(0, jsFiles.length).forEach(i -> {
        try {
            context.evaluateReader(globalScope, new FileReader(jsFiles[i]), "ECMAScriptExecutor", 1, null);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });

    String res = "expect(false).to.not.be.test";
    context.evaluateString(globalScope, res, "ECMAScriptExecutor", 1, null);

}
please suggest me what would be issue here
thanks in advance
Guillermo Cabrera
@guicaro_twitter
hello everyone, maybe a very simple question, but how can evaluate an Assertion in chaijs? In other words, how can I know in a console.log statement whether the below expect() is true or false?
expect(1).to.equal(1);