This is resolved by upgrading to the latest version of Chutzpah.
Chutzpah Error: Object doesn't support property or method 'filter'
-
29-06-2022 - |
Pergunta
I'm trying to run jasmine tests on my knockout viewmodels, written in typescript via chutzpah but this doesn't seem possible due to the following error:
Chutzpah Error: Object doesn't support property or method 'filter'
This error gets thrown whenever I access a knockout observable and can be recreated via the following simple example.
/// <reference path="../../typings/jquery/jquery.d.ts" />
/// <reference path="../../typings/knockout/knockout.d.ts" />
/// <reference path="../../typings/jasmine/jasmine.d.ts" />
module Example {
export class KnockoutClass {
public anObservable = ko.observable<string>();
public aComputed = ko.computed<boolean>(() => {
return this.anObservable().length() > 5;
});
}
}
describe("This", () => {
it(" will throw an error", () => {
var temp: Example.KnockoutClass = new Example.KnockoutClass();
});
});
Am I doing something fundamentally wrong here or is chutzpah not compatible with the knockout/typescript combination?
UPDATE
So I've managed to get chutzpah to run my tests by doing the following:
- Remove the 'Jasmine Test Framework' NuGet package from my project and replace it with the 'jasmine.js' NuGet package instead.
- Add a jasmine specrunner.html file to my tests directory that references my tests and their dependencies
- In Tools->Options->Chutzpah->Unit Test Explorer set Testing Mode to HTML
- Run tests from the Test Explorer window
This gets my tests running successfully but I still get the same exception when I try to run by right click->'Run JS Tests' and I can't debug tests either.
The issue seems to be that none of my references are resolved (the filter method is defined within jquery) so maybe I need to use require.js or some other module loader to resolve my dependencies?
Solução