Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 10:49

    keithamus on main

    docs: fix URL in README (#1413) (compare)

  • 10:49
    keithamus closed #1413
  • 09:40
    Izzur review_requested #1413
  • 09:40
    Izzur opened #1413
  • Sep 16 10:51
    orcuan synchronize #275
  • Sep 15 17:56
    jrobinson01 commented #1411
  • Sep 15 16:57
    keithamus commented #146
  • Sep 10 07:22
    sukrosono commented #1409
  • Sep 10 01:32
    sukrosono commented #1408
  • Sep 07 18:12
    keithamus commented #198
  • Sep 07 18:12

    keithamus on master

    Ban un-maintened fork of sinon-… (compare)

  • Sep 07 18:12
    keithamus closed #198
  • Sep 02 15:52
    Alloyed opened #146
  • Aug 30 08:39
    fncolon edited #298
  • Aug 30 08:34
    fncolon commented #298
  • Aug 30 07:07
    fncolon edited #298
  • Aug 30 07:06
    fncolon edited #298
  • Aug 30 07:05
    fncolon closed #298
  • Aug 30 07:05
    fncolon commented #298
  • Aug 30 04:35
    fncolon opened #298
Isabel Giang
@hollowsunsets
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);
Jon Lauridsen
@gaggle

Hi, is it currently possible to assert something like this?

expect([ {foo: "ham"}, {foo: "spam"}, {foo: "bacon"} ]).to.have.properties("foo", ["ham", "spam", "bacon"])

If not I'll make a custom helper, but maybe I've missed something in the existing ecosystem..

khizerrehan
@KhizerRehan
@guicaro_twitter i think you can simply do console.log(1===1); this will assert as a Boolean value and below you can add expect(1).to.equal(1)
Dev
@Charan83
Hi
Is there a way to do soft assertions
Kwirke
@kwirke

Hi
Is there a way to do soft assertions

Hi Dev! Assuming that "soft assertions" means assertions that when fail, they are logged, but don't stop the test.
Chai, and most other assertion libs, work by throwing an exception whenever an assertion fails. This means you can catch that exception and treat it yourself:

const softAssert = fn => {
  try {
    fn()
    return null
  } catch (e) {
   return e
  }
}

it('should work', () => {
  const error = softAssert(() => expect(actual).to.equal(expected))
  const error2 = softAssert(() => ...)
  ...
})

However! Take into account that having to do this is a signal that your code may be reliying in exceptions to do normal work, which can lead to convoluted flows. It is better if your code is made to handle error cases with different returned types, instead of exceptions that may or may not be captured at different levels in the architecture.
To know more, I recommend this article: https://blog.logrocket.com/elegant-error-handling-javascript-either-monad/

Leonardo Properzi
@lhimo
Hi all, is there a way to assert that each element of an array contains a certain array property, and each of this second array contains a certain property? I'm trying to chain two chai-each command like this response.body.array1.should.each.have.property('array2').that.should.each.have.property('property') but I get: AssertionError: expected { Object (__flags) } to be an instance of Array
1 reply
Leonardo Properzi
@lhimo
Hi! Me again :) Is there a way to filter array elements based on certain values? eg. in this json { array: [ { element1: Mario, element2: White }, { element1: Luigi, element2: Green } ] } I want to check that the element of array which has element1 equal to Mario has element2 equal to White
2 replies
Justice
@Justiceankomah3_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? I definitely want to share this here too https://tutorialscamp.com/
expect(1).to.equal(1);
Marc
@MarcNq
Hi @Justiceankomah3_twitter ,
Here's how assertions work:
A test is just a smart try-catch block. If an exception occurs inside, the test fails. Assertions are just functions that throw well formatted exceptions.
If you needed to know if an assertion works, you can wrap it in a try-catch yourself, and re-throw it in the catch:
try {
  expect(1).to.equal(2)
} catch (failedAssertion) {
  console.log(failedAssertion)
  throw failedAssertion
}
Stjepan Jakovac
@sJakovac

Is it possible to test if array contians objects that are superset of target objects. For examle, I'd like following to pass:

var value_under_test = [ {id: 5, name: "N1"}, {id:6, name: "N2"}]
var assertion_value = [{id:5}, {id: 6}]
expect(value_under_test).to. have.????.(assertion_value)

I know I can first map value_under_test and then to.have.deep.members but that can get ugly if I have to pick more than one key

1 reply
NickWoodward
@NickWoodward
This message was deleted