question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use chai directly instead of internal `eq` function in test asserts

See original GitHub issue

Appropriate assert functions from chai should be used to be more explicit.

Code like this:

describe('ensureArray', function() {
  context('given argument is not an array', function() {
    specify('should wrap value into singleton array', function() {
      const arrayPrototype = Array.prototype;

      eq(RA.ensureArray(void 0), [void 0]);
      eq(RA.ensureArray({}), [{}]);
      eq(RA.ensureArray(null), [null]);
      eq(RA.ensureArray(undefined), [undefined]);
      eq(RA.ensureArray(42), [42]);
      eq(RA.ensureArray('Array'), ['Array']);
      eq(RA.ensureArray(true), [true]);
      eq(RA.ensureArray(false), [false]);
      eq(RA.ensureArray({ __proto__: arrayPrototype }), [
        { __proto__: arrayPrototype },
      ]);
    });
  });
});

has to become like this:

import { assert } from 'chai';

describe('ensureArray', function() {
  context('given argument is not an array', function() {
    specify('should wrap value into singleton array', function() {
      const arrayPrototype = Array.prototype;

      assert.sameOrderedMembers(RA.ensureArray(void 0), [void 0]);
      assert.sameDeepOrderedMembers(RA.ensureArray({}), [{}]);
      assert.sameOrderedMembers(RA.ensureArray(null), [null]);
      assert.sameOrderedMembers(RA.ensureArray(undefined), [undefined]);
      assert.sameOrderedMembers(RA.ensureArray(42), [42]);
      assert.sameOrderedMembers(RA.ensureArray('Array'), ['Array']);
      assert.sameOrderedMembers(RA.ensureArray(true), [true]);
      assert.sameOrderedMembers(RA.ensureArray(false), [false]);
      assert.sameDeepOrderedMembers(
        RA.ensureArray({ __proto__: arrayPrototype }),
        [{ __proto__: arrayPrototype }]
      );
    });
  });

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:34 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
js636fcommented, Nov 26, 2019

@char0n, here is Batch 20 PR

1reaction
js636fcommented, Nov 25, 2019

@char0n, here is Batch 19 PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript — Unit Testing using Mocha and Chai - codeburst
This article will cover testing of basic function, testing of async callback functions and testing of promises with Mocha and Chai.
Read more >
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai, Sinon ...
Asserts that the target has a property name, optionally asserting that the value of that property is strictly equal to value. If the...
Read more >
Core Plugin Concepts - Chai Assertion Library
This tutorial will show you how to access Chai's plugin API, use flags to transfer data through the language chain, and write your...
Read more >
Unit testing Node.js applications using Mocha, Chai, and Sinon
In this article, we will look at how to use Mocha for testing, Chai for assertions and Sinon for mocks, spies, and stubs....
Read more >
How do I test if a function calls a specific method/function?
I am using Mocha with Chai, but am open to any other assertion libraries. Ok, so testing whether a methid is being called...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found