Invalid Chai property: called. Did you mean "all"? - javascript

I am trying to test my node.js code using Mocha, Sinon, and chai.
var callback = function (err, resultSet) {
should.exist(resultSet);
stubbedExecuteSqlQuery.should.be.called;
done();
};
stubbedExecuteSqlQuery.yields(null, expectedResultSet);
db.getResults(param1,param2, user, callback);
when the above code gets executed, it throws an error :
Invalid Chai property: called. Did you mean "all"?
The code used to work fine on chai version ^3.5.0 but after my recent package upgrade to ^4.1.2 the code has stopped working and has started throwing such errors.
I tried searching for it on the internet but could not find any useful information.
Any help will be appreciated. Thanks in advance!

I had a similar issue, I think it had something to do with using .yields
I ended up using .calledOnce . Try the following:
assert(stubbedExecuteSqlQuery.calledOnce);
The upside with this is that if needed you can do .calledTwice etc..

Related

TypeError: Cannot read property 'toBeA' of undefined

I am trying to test my code using expect in nodejs. I required expect in code and I wanted to use a feature of expect called toBeA(). But unfortunately I
am receiving error and unable to solve it. So,I am posting it here.
const utils = require('./utils');
const expect = require('expect');
it('should add two numbers', () => {
var result = utils.add(33,17);
expect(result).toBe(50).toBeA('number');
});
This is my utils.js file
module.exports.add = (a,b) => {
return a+b;
};
When I run the code I receive this error
TypeError: Cannot read property 'toBeA' of undefined
You cannot chain tests. toBe doesn't return anything, hence the error. You want
expect(result).toBe(50);
expect(result).toBeA('number');
(although the first one implies the other so you might as well omit it)
This works fine instead of toBeA()
expect(typeof result).toBe('number');
The expect assertion library has changed ownership. It was handed over to the Jest team, who in their infinite wisdom, created a new API.
You can still install expect as before, "npm install expect --save-dev", which is currently at version 21.2.1. Most methods names will remain unchanged except for a few, including 'toExist(), toBeA()'.
when use npm i expect --save-dev command for install expect, automatically install last version of expect. in last version chain do not work.
for solve this problem you should use below command:
npm i expect#1.20.2
in this version you can use chain expect like toNotBe.

`waitForEnabled()` says "selector needs to be typeof `string`" even though string was passed

I was originally using the mocha command line tool to run my tests and they were working fine. I switched to using the wdio command to run my tests. My tests now throw an error with this line of code:
browser.waitForEnabled('#div_id');
With this error:
Promise was rejected with the following reason: Error: selector needs to be typeof `string`
running chrome
Error: Promise was rejected with the following reason: Error: selector needs to be typeof `string`
at elements() - isEnabled.js:18:17
at isEnabled() - waitForEnabled.js:37:22
This was working fine until I started using wdio (specifically I run wdio --spec path/to/file.js). I've run the typeof function on the selector in question and verified that it is, in fact, a string.
The div in question looks like this:
<div class="highlight" id="div_id">
A fair bit of content goes here.
</div>
Why am I seeing this error? How do I fix it?
waitForEnabled() documentation => http://webdriver.io/api/utility/waitForEnabled.html
wdio documentation => http://webdriver.io/guide/testrunner/gettingstarted.html
Update:
I've tried adding a timeout to the waitForEnabled() function. Since I've done so, it sometimes fails, and sometimes does not. More often it fails though.
I'm not marking this as the answer because I have no idea why it works. But passing in all of the optional params to waitForEnabled() makes it work just fine.
As in:
waitForEnabled('#div_id'); Fails. Wheras:
waitForEnabled('#div_id', 99999, false); works without errors.
The fact that you're passing milliseconds & the false option should not make the test pass.
I'd suggest using some of the other waitFor commands, like waitForVisible() or waitForExist(), because I'm assuming this is what you really want from the code example you gave above. The waitForEnabled() command waits for a field that had a disabled html attribute, to not have it anymore. You can read more on that here: https://www.w3schools.com/tags/att_disabled.asp.

TypeError: element(...).then is not a function in Protractor 3.2.1

I was using following code
element(by.xpath("//tf-navpane-item[contains(#class,'tf-state-selected')]//tf-navpane-item-text//*[contains(#class,'ng-binding')]")).then(function(ele){
ele.getText().then(function(txt){
console.log("txt: "+txt);
});
});
This code used to work fine when I was using Protractor 1.0. After upgrading Protractor to 3.2.1 ,I started to get following error.
TypeError: element(...).then is not a function
I maybe missing something but not sure what.
Yeah, this is something you should expect since the element() cannot be directly resolved with then() anymore (breaking change in Protractor 2.0). Instead, do:
var elm = element(by.xpath("//tf-navpane-item[contains(#class,'tf-state-selected')]//tf-navpane-item-text//*[contains(#class,'ng-binding')]"));
elm.getText().then(function(txt) {
console.log("txt: " + txt);
});
Note that, if you would need to assert the text, you can pass the getText() into expect() - it understands what a promise is and would resolve it before making an expectation:
expect(elm.getText()).toEqual("Expected text");

Meteor server throws error with Accounts.addEmail() in a meteor method

I need help figuring out why I am getting this error.
My method is defined in app/server/methods.js
Meteor.methods({
myMethod: function(user) {
Accounts.addEmail(user._id, "thisemail#email.com", true); // set verified to true
}
});
My template has an event that is calling this method from the client.
Template.myTemplate.events({
'click #this-button': function(e) {
Meteor.call("myMethod", userObject, function(error, result) {
if (error) {
console.log(error);
} else {
// do something here
}
});
}
});
I keep getting an Internal Server Error [500] error back to the console.
When I check my server output it says:
Exception while invoking method 'myMethod' TypeError: Object #<Object> has no method 'addEmail'.
Can anyone help me figure out why it can't be found/used?
These are the list of packages I am using, and I thought this came packaged with the accounts-password package according to the Meteor Documentation here.
meteor-platform
iron:core
iron:router
less
zimme:iron-router-active
tomi:upload-server
tomi:upload-jquery
houston:admin
coffeescript
alanning:roles
edgee:slingshot
joshowens:accounts-entry
mystor:device-detection
underscore
email
accounts-password
If I'm reading the commit history correctly, it looks like addEmail was added here as part of meteor 1.2.
The docs always reference the latest version, but your app is using version 1.1, which explains the missing function.
The solution may be as simple as running meteor update, however accounts-entry is ancient and it may be incompatible with meteor 1.2, as noted in this issue.
If you can't or don't want to update, just leave a comment and I can suggest an alternative implementation.

How do I log everything with sentry/raven-js

I'm working on an existing project, with a lot of webpages. My task is to introduce logging og client script errors, usingsentr/raven-js.
In the docs, it says that i need to wrap the functions that I need to track in try/catch blocks - this is familiar to me, since I usually work in C#. But I don't wat to edit alle pages to wrap ALL javascript functions in try/catch. Is there a way to log ALL errors?
I tried something with window.onError = Raven.process, but I didn't get any logentries.
Can someone show me a what I'm missing? My setup is this:
var options = {
logger: 'my-test-logger',
whitelistUrls: [
/localhost/,
/localhost:2109/
]
};
Raven.config('https://<public-key-removed>#app.getsentry.com/<project-key-removed>', options).install();
window.onerror = Raven.process;
My setup was correct, except for the line:
window.onerror = Raven.process
For some reason I couldn't provoke any error to fire the logging event, but once I managed to simulate a real error, the logging worked just fine. The line:
Raven.config('https://#app.getsentry.com/', options).install();
does catch all errors.
It is important to realize that raven does not capture errors you trigger with the console. You need to put some error generating code directly in the page, or do something like this from the console:
window.setTimeout(function(){ foo() });
Also, i think that doing:
window.onerror = Raven.process
Is unnecessary, Raven already does that for you, in a much more advanced way.
Try the following code to disable logs from raven.js
Raven.config('your dsn', {
autoBreadcrumbs: {
console: false
}
});
Raven will from version 1 log all window.onerror errors by default.
See https://raven-js.readthedocs.org/en/latest/config/index.html#collectwindowerrors

Categories

Resources