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.

Cannot use 'should' assertion style with mocha / chai / chai-as-promised

See original GitHub issue

I tried to use myElement.getText().should.eventually.equal("foo") as in the chai-as-promised manual, but got TypeError: Cannot read property 'eventually' of undefined. This is not a problem with chai-as-promised either, because myElement.getText().should.equal("foo") failed with a similar error. Using expect works as expected, though.

var chai = require('chai');
chai.use(require('chai-as-promised'));
var should = chai.should();

describe('Home', function() {
  it('should say hello', function() {
    browser.get('/');
    $('h1').getText().should.eventually.equal('Hello, world');
  });
});

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
jodytatecommented, May 22, 2015

@vladei I received a similar error until I confirmed the following as the correct order:

var chai = require('chai');
var should = chai.should();
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);

Object.defineProperty(
  protractor.promise.Promise.prototype,
  'should',
  Object.getOwnPropertyDescriptor(Object.prototype, 'should')
);
0reactions
juliemrcommented, Dec 22, 2016

Sweet, closing as fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chai Assertions for Promises
Chai as Promised extends Chai with a fluent language for asserting facts about ... the existing format of assertions being used on a...
Read more >
expecting promised to resolve or reject doesn't properly fail a ...
My suggestion above just to show different style on how to use chai-as-promise, and since ewok asked on how to put several assertions...
Read more >
JavaScript — Unit Testing using Mocha and Chai - codeburst
Assertion with Chai provides expressive language & readable style like below test. In below sample test, we put assertion like car.should.have.
Read more >
Mocha - the fun, simple, flexible JavaScript test framework
This means you can use libraries such as: should.js - BDD style shown throughout these docs; expect.js - expect() style assertions; chai -...
Read more >
How to use the chai.should function in chai - Snyk
'use strict'; /* eslint-disable max-len, no-console, padded-blocks, no-multiple-empty-lines */ /* eslint-env node,mocha */ // These tests make use of ...
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