CopyPastor

Detecting plagiarism made easy.

Score: 1; Reported for: Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2023-05-09
by user2340939

Original Post

Original - Posted on 2014-02-05
by Louis



            
Present in both answers; Present only in the new answer; Present only in the old answer;

> You have to pass a function to expect. Like this:
expect(model.get.bind(model, 'z')).to.throw('Property does not exist in model schema.'); expect(model.get.bind(model, 'z')).to.throw(new Error('Property does not exist in model schema.'));
Source: https://stackoverflow.com/questions/21587122/mocha-chai-expect-to-throw-not-catching-thrown-errors?rq=1
You have to pass a function to `expect`. Like this:
expect(model.get.bind(model, 'z')).to.throw('Property does not exist in model schema.'); expect(model.get.bind(model, 'z')).to.throw(new Error('Property does not exist in model schema.'));
The way you are doing it, you are passing to `expect` the *result* of calling `model.get('z')`. But to test whether something is thrown, you have to pass a function to `expect`, which `expect` will call itself. The `bind` method used above creates a new function which when called will call `model.get` with `this` set to the value of `model` and the first argument set to `'z'`.
A good explanation of `bind` can be found [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind).

        
Present in both answers; Present only in the new answer; Present only in the old answer;