Gathering detailed insights and metrics for codeceptjs-chai
Gathering detailed insights and metrics for codeceptjs-chai
Gathering detailed insights and metrics for codeceptjs-chai
Gathering detailed insights and metrics for codeceptjs-chai
npm install codeceptjs-chai
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
10 Stars
64 Commits
9 Forks
1 Watching
4 Branches
9 Contributors
Updated on 18 Oct 2024
Minified
Minified + Gzipped
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
1.4%
3,870
Compared to previous day
Last week
3.4%
23,322
Compared to previous week
Last month
2.1%
99,979
Compared to previous month
Last year
11.2%
1,289,937
Compared to previous year
codeceptjs-chai is CodeceptJS helper which wraps chai library to complete chai assertion steps with CodeceptJS logging. This wrapper allow us to print asserts as steps in output. Also we can expand this lib with different methods and other assertion libraries.
NPM package: https://www.npmjs.com/package/codeceptjs-chai
This helper should be added in codecept.json/codecept.conf.js
Example:
1{ 2 "helpers": { 3 "ChaiWrapper": { 4 "require": "codeceptjs-chai" 5 } 6 } 7}
Asserts that the target is strictly (===) equal to the given value.
https://www.chaijs.com/api/bdd/#method_equal
1I.assertEqual(1, 1);
2I.assertEqual("foo", "foo");
3I.assertEqual("foo", "foo", "Both the values are not equal");
Parameters
actualValue
- actual valueexpectedValue
- expected valuecustomErrorMsg
- Custom error messageAsserts that the target is not equal to the given value.
1I.assertNotEqual(2, 1);
2I.assertNotEqual("foobar", "foo");
3I.assertNotEqual("foobar", "foo", "Both the values are equal");
Parameters
actualValue
- actual valueexpectedValue
- expected valuecustomErrorMsg
- Custom error messageAsserts that the target is an object whose properties are strictly equal (===) as the given value's.
1I.assertDeepEqual({ a: 1 }, { a: 1 });
Parameters
actualValue
- actual valueexpectedValue
- expected valuecustomErrorMsg
- Custom error messageAsserts that the target is not an object whose properties are strictly equal (===) as the given value's.
1I.assertNotDeepEqual({ a: 1 }, { a: 2 });
2I.assertNotDeepEqual({ a: 1 }, { b: 1, c: 2 });
3I.assertNotDeepEqual(
4 { a: 1 },
5 { b: 1, c: 2 },
6 "Both the values are deeply equal"
7);
Parameters
actualValue
- actual valueexpectedValue
- expected valuecustomErrorMsg
- Custom error messageAsserts that the target contains the given value.
https://www.chaijs.com/api/bdd/#method_include
1I.assertContain("foobar", "foo");
2I.assertContain([1, 2, 3], 2);
3I.assertContain({ a: 1, b: 2, c: 3 }, { a: 1, b: 2 });
4I.assertContain(new Set([1, 2]), 2);
5I.assertContain(
6 new Map([
7 ["a", 1],
8 ["b", 2],
9 ]),
10 2
11);
12I.assertContain("foobar", "foo", "Target value does not contain given value");
Parameters
actualValue
- actual valueexpectedValueToContain
- expected value to containcustomErrorMsg
- Custom error messageAsserts that the target does not contain the given value.
1I.assertNotContain("foo", "bar");
2I.assertNotContain([1, 2, 3], 4);
3I.assertNotContain({ a: 3, b: 4 }, { a: 1, b: 2 });
4I.assertNotContain("foo", "bar", "Target value contains given value");
Parameters
actualValue
- actual valueexpectedValueToNotContain
- expected value to not containcustomErrorMsg
- Custom error messageAsserts that the target starts with the given value.
https://www.npmjs.com/package/chai-string#startswithstartwith
1I.assertStartsWith("foobar", "foo");
2I.assertStartsWith(
3 "foobar",
4 "foo",
5 "Target value does not start with given value"
6);
Parameters
actualValue
- actual valueexpectedValueToStartWith
- expected value to start withcustomErrorMsg
- Custom error messageAsserts that the target does not start with the given value.
1I.assertNotStartsWith("foobar", "bar");
2I.assertNotStartsWith("foobar", "bar", "Target value starts with given value");
Parameters
actualValue
- actual valueexpectedValueToNotStartWith
- expected value to not start withcustomErrorMsg
- Custom error messageAsserts that the target ends with the given value.
https://www.npmjs.com/package/chai-string#endswithendwith
1I.assertEndsWith("foobar", "bar");
2I.assertEndsWith(
3 "foobar",
4 "bar",
5 "Target value does not ends with given value"
6);
Parameters
actualValue
- actual valueexpectedValueToEndWith
- expected value to end withcustomErrorMsg
- Custom error messageAsserts that the target does not end with the given value.
1I.assertNotEndsWith("foobar", "bar");
2I.assertNotEndsWith("foobar", "bar", "Target value ends with given value");
Parameters
actualValue
- actual valueexpectedValueToNotEndWith
- expected value to not end withcustomErrorMsg
- Custom error messageValidate that the given json data conforms to the specified JSON Schema. Both the value and schema would likely be JSON loaded from an external datasource but could also be literals or object instances.
https://www.npmjs.com/package/chai-json-schema#jsonschemavalue-schema
1const goodApple = { 2 skin: "thin", 3 colors: ["red", "green", "yellow"], 4 taste: 10, 5}; 6const badApple = { 7 colors: ["brown"], 8 taste: 0, 9 worms: 2, 10}; 11const fruitSchema = { 12 title: "fresh fruit schema v1", 13 type: "object", 14 required: ["skin", "colors", "taste"], 15 properties: { 16 colors: { 17 type: "array", 18 minItems: 1, 19 uniqueItems: true, 20 items: { 21 type: "string", 22 }, 23 }, 24 skin: { 25 type: "string", 26 }, 27 taste: { 28 type: "number", 29 minimum: 5, 30 }, 31 }, 32}; 33I.assertJsonSchema(goodApple, fruitSchema); 34I.assertJsonSchema( 35 goodApple, 36 fruitSchema, 37 "Target json data does not conform to json schema" 38);
Parameters
targetData
- target json datajsonSchema
- json schemacustomErrorMsg
- Custom error messageValidate that the given json data conforms to the specified JSON Schema using chai-json-schema-ajv. Both the value and schema would likely be JSON loaded from an external datasource but could also be literals or object instances.
1const goodApple = { 2 skin: "thin", 3 colors: ["red", "green", "yellow"], 4 taste: 10, 5}; 6const badApple = { 7 colors: ["brown"], 8 taste: 0, 9 worms: 2, 10}; 11const fruitSchema = { 12 title: "fresh fruit schema v1", 13 type: "object", 14 required: ["skin", "colors", "taste"], 15 properties: { 16 colors: { 17 type: "array", 18 minItems: 1, 19 uniqueItems: true, 20 items: { 21 type: "string", 22 }, 23 }, 24 skin: { 25 type: "string", 26 }, 27 taste: { 28 type: "number", 29 minimum: 5, 30 }, 31 }, 32}; 33I.assertJsonSchemaUsingAJV(goodApple, fruitSchema); 34I.assertJsonSchema( 35 goodApple, 36 fruitSchema, 37 "Target json data does not conform to json schema", 38 {} 39); 40I.assertJsonSchema(goodApple, fruitSchema, "", { jsonPointers: true });
Parameters
targetData
- target json datajsonSchema
- json schemacustomErrorMsg
- Custom error messageajvOptions
- Custom AJV OptionsAsserts that the target has a property with the given key.
https://www.chaijs.com/api/bdd/#method_property
1I.assertHasProperty({ a: 1 }, "a");
2I.assertHasProperty(
3 { a: 1 },
4 "a",
5 "Target data does not have the given property"
6);
Parameters
targetData
- target json datapropertyName
- expected property namecustomErrorMsg
- Custom error messageAsserts that the target has a child property with the given key.
https://www.chaijs.com/api/bdd/#method_a
1I.assertHasAProperty({ b: 2 }, "b");
2I.assertHasAProperty(
3 { b: 2 },
4 "b",
5 "Target data does not have a child property with the given key"
6);
Parameters
targetData
- target json datapropertyName
- expected property namecustomErrorMsg
- Custom error messageAsserts that the target’s type is equal to the given string type. Types are case insensitive. See the type-detect project page for info on the type detection algorithm: https://github.com/chaijs/type-detect.
https://www.chaijs.com/api/bdd/#method_a
1I.assertToBeA("foo", "string");
2I.assertToBeA(null, "null");
3I.assertToBeA(Promise.resolve(), "promise");
4I.assertToBeA(new Float32Array(), "float32array");
5I.assertToBeA(Symbol(), "symbol");
6I.assertToBeA("foo", "string", "Target data does not match the type");
Parameters
targetData
- target json datatype
- expected data typecustomErrorMsg
- Custom error messageAsserts that the target’s type is equal to the given string type. Types are case insensitive. See the type-detect project page for info on the type detection algorithm: https://github.com/chaijs/type-detect.
https://www.chaijs.com/api/bdd/#method_a
1I.assertToBeAn([1, 2, 3], "array");
2I.assertToBeAn({ a: 1 }, "object");
3I.assertToBeAn(undefined, "undefined");
4I.assertToBeAn(new Error(), "error");
5I.assertToBeAn([1, 2, 3], "array", "Target data does not match the type");
Parameters
targetData
- target json datatype
- expected data typecustomErrorMsg
- Custom error messageAsserts that the target matches the given regular expression.
https://www.chaijs.com/api/bdd/#method_match
1I.assertMatchRegex("foobar", /^foo/);
2I.assertMatchRegex(
3 "foobar",
4 /^foo/,
5 "Target data does not match the given regex"
6);
Parameters
targetData
- target json dataregex
- regular expression to match target datacustomErrorMsg
- Custom error messageAsserts that the target’s length or size is equal to the given number n.
https://www.chaijs.com/api/bdd/#method_lengthof
1I.assertLengthOf([1, 2, 3], 3); 2I.assertLengthOf("foo", 3); 3I.assertLengthOf(new Set([1, 2, 3]), 3); 4I.assertLengthOf( 5 new Map([ 6 ["a", 1], 7 ["b", 2], 8 ["c", 3], 9 ]), 10 3 11); 12I.assertLengthOf("foo", 3, "Target data does not match the length");
Parameters
targetData
- target json datalength
- expected target data lengthcustomErrorMsg
- Custom error messageWhen the target is a string or array, .empty asserts that the target’s length property is strictly (===) equal to 0.
https://www.chaijs.com/api/bdd/#method_empty
1I.assertEmpty("");
2I.assertEmpty([]);
3I.assertEmpty({});
4I.assertEmpty(new Set());
5I.assertEmpty(new Map());
6I.assertEmpty("", "Target data is not empty");
Parameters
targetData
- target json datacustomErrorMsg
- Custom error messageAsserts that the target is strictly (===) equal to true.
https://www.chaijs.com/api/bdd/#method_true
1I.assertTrue(true);
2I.assertTrue(true, "Target data is not true");
Parameters
targetData
- target datacustomErrorMsg
- Custom error messageAsserts that the target is strictly (===) equal to false.
https://www.chaijs.com/api/bdd/#method_false
1I.assertFalse(false);
2I.assertTrue(false, "Target data is not false");
Parameters
targetData
- target datacustomErrorMsg
- Custom error messageAsserts that the target is a number or a date greater than the given number or date n respectively. However, it’s often best to assert that the target is equal to its expected value.
https://www.chaijs.com/api/bdd/#method_above
1I.assertAbove(2, 1);
2I.assertAbove(2, 1, "Target data not above the given value");
Parameters
targetData
- target dataaboveThan
- number | DatecustomErrorMsg
- Custom error messageAsserts that the target is a number or a date less than the given number or date n respectively. However, it’s often best to assert that the target is equal to its expected value.
https://www.chaijs.com/api/bdd/#method_below
1I.assertBelow(1, 2);
2I.assertAbove(1, 2, "Target data not below the given value");
Parameters
targetData
- target databelowThan
- number | DatecustomErrorMsg
- Custom error messageAsserts that the target’s length or size is equal to the given number n.
https://www.chaijs.com/api/bdd/#method_lengthof
1I.assertLengthOf([1, 2, 3], 3); 2I.assertLengthOf("foo", 3); 3I.assertLengthOf(new Set([1, 2, 3]), 3); 4I.assertLengthOf( 5 new Map([ 6 ["a", 1], 7 ["b", 2], 8 ["c", 3], 9 ]), 10 3 11); 12I.assertLengthOf( 13 "foo", 14 3, 15 "Target length or size does not match the given number" 16);
Parameters
targetData
- target dataexpectedLength
- expected lengthcustomErrorMsg
- Custom error messageAsserts that the target’s length or size is above than the given number n.
https://www.chaijs.com/api/bdd/#method_lengthof https://www.chaijs.com/api/bdd/#method_above
1I.assertLengthAboveThan([1, 2, 3], 2); 2I.assertLengthAboveThan("foo", 2); 3I.assertLengthAboveThan(new Set([1, 2, 3]), 2); 4I.assertLengthAboveThan( 5 new Map([ 6 ["a", 1], 7 ["b", 2], 8 ["c", 3], 9 ]), 10 2 11); 12I.assertLengthAboveThan( 13 "foo", 14 2, 15 "Target length or size not above than given number" 16);
Parameters
targetData
- target datalengthAboveThan
- length above thancustomErrorMsg
- Custom error messageAsserts that the target’s length or size is below than the given number n.
https://www.chaijs.com/api/bdd/#method_lengthof https://www.chaijs.com/api/bdd/#method_below
1I.assertLengthBelowThan([1, 2, 3], 4); 2I.assertLengthBelowThan("foo", 4); 3I.assertLengthBelowThan(new Set([1, 2, 3]), 4); 4I.assertLengthBelowThan( 5 new Map([ 6 ["a", 1], 7 ["b", 2], 8 ["c", 3], 9 ]), 10 4 11); 12I.assertLengthAboveThan( 13 "foo", 14 4, 15 "Target length or size not below than given number" 16);
Parameters
targetData
- target datalengthBelowThan
- length below thancustomErrorMsg
- Custom error messageAsserts two strings represent the same value when ignoring case
https://www.chaijs.com/plugins/chai-string/
1I.assertEqualIgnoreCase("FOO", "foo");
Parameters
actualValue
- actual valueexpectedValue
- expected valuecustomErrorMsg
- Custom error messageAsserts members of two arrays are deeply equal
https://www.chaijs.com/api/bdd/#method_deep
1I.assertDeepMembers([{ a: 1 }], [{ a: 1 }]);
Parameters
actualValue
- actual valueexpectedValue
- expected valuecustomErrorMsg
- Custom error messageAsserts an array deep includes members from another array
https://www.chaijs.com/api/bdd/#method_deep
1I.assertDeepIncludeMembers([{ a: 1 }, { b: 2 }], [{ a: 1 }]);
Parameters
actualValue
- actual valueexpectedValue
- expected valuecustomErrorMsg
- Custom error messageAsserts members of two JSON objects are deeply equal excluding some properties
https://www.chaijs.com/plugins/chai-exclude/
1I.assertDeepEqualExcluding([{ a: 1 }, { b: 2 }], "b", [{ a: 1 }]);
Parameters
actualValue
- actual valueexpectedValue
- expected valuefieldsToExclude
- Fields to exclude from validationcustomErrorMsg
- Custom error messageAsserts a JSON object matches a provided pattern
https://www.chaijs.com/plugins/chai-match-pattern/
1I.assertMatchesPattern({ a: 1, b: "abc" }, { a: 1, b: _.isString });
Parameters
actualValue
- actual valueexpectedPattern
- pattern to match oncustomErrorMsg
- Custom error messageNo vulnerabilities found.
Reason
no binaries found in the repo
Reason
Found 7/10 approved changesets -- score normalized to 7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
11 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More