草庐IT

testing-backbone-apps-with-jasmin

全部标签

javascript - Jasmine 测试在 Chrome 和 Firefox 中通过,但在 PhantomJS 中失败

我正在使用React构建一个基本的博客应用程序。我正在使用Jasmine和Karma来运行我的前端测试。我启动并运行了第一个测试,它在Chrome(Chromium)和Firefox中通过了测试,但是当它在PhantomJS中运行时,我收到以下错误:PhantomJS1.9.8(Linux0.0.0)ERRORTypeError:'undefined'isnotafunction(evaluating'ReactElementValidator.createElement.bind(null,type)')at/home/michael/repository/short-stories

javascript - Backbone.js:如何通过模型 ID 数组过滤对象集合?

我有一个充满模型的Backbone.Collection;假设模型是Car。这个集合是一个非常大的Cars列表。我希望能够从列表中选择一些特定的汽车ID,然后能够从该集合中仅获取那些选定的汽车对象。我下面的代码块不工作;我确信有一种方法可以使用Backbone.js/Underscore.js来实现这一点……我对Backbone/Underscore也很陌生。CarList=Backbone.Collection.extend({model:Car,filterWithIds:function(ids){returnthis.filter(function(aCar){return_.

javascript - 默认的 Backbone 事件是什么?

我在这里有点懒,但这些(下面)是所有默认的Backbone事件。另外,我说事件冒泡是正确的,所以集合将接收模型触发的任何事件。Backbone模型事件改变错误同步销毁征集事件添加移除同步重置非常感谢懒惰的尼克 最佳答案 来自Backbone网站(http://backbonejs.org/#Events-catalog):事件目录这是Backbone.js可以触发的所有内置事件的列表。您还可以根据需要在模型和View上自由触发自己的事件。“添加”(模型、集合、选项)——将模型添加到集合时。"remove"(模型、集合、选项)——当模

javascript - QUnit、Sinon.js 和 Backbone 单元测试受挫 : sinon spy appears to fail to detect Backbone Model event callbacks

在下面的单元测试代码中:TestModel=Backbone.Model.extend({defaults:{'selection':null},initialize:function(){this.on('change:selection',this.doSomething);},doSomething:function(){console.log("Somethinghasbeendone.");}});module("Test",{setup:function(){this.testModel=newTestModel();}});test("intra-modeleventbi

javascript - 测试 Jasmine 中自定义事件的处理

我想确保在触发自定义jQuery事件时,对象的方法作为事件处理程序被调用;但是单元测试似乎返回了假阴性,因为我的实现效果很好。(这是使用TwitterFlight和FlightJasmineextensions的测试套件的一部分,但这只是一个普通的Jasminespy。)describe('listeningforuiNeedsPlanevent',function(){varspy;beforeEach(function(){spy=spyOn(this.component,'getPlan');$(document).trigger('uiNeedsPlan');});it('ge

javascript - Angular JS : ng-repeat with dynamic ng-model

我有一段重复多次的有效代码,因此非常适合ng-repeat循环。例如,我的代码的两个实例如下。这是Javascript中的filterParamDisplay数组:$scope.filterParamDisplay=[{param:'userName',displayName:'UserName'},{param:'userEmail',displayName:'UserEmail'}];我一直在尝试将其放入ng-repeat循环中,但到目前为止没有成功。这就是我对atm进行的编码。问题在于上面的ng-model变量,以及ng-click和ng-show中的$index。不确定这是否可

javascript - 如何在 Node JS FS 模块中使用 Typescript Async/await with promise

如何在nodejsFS模块中使用Typescriptasync/await函数并返回typescript默认promise,并在promise解决后调用其他函数。代码如下:if(value){tempValue=value;fs.writeFile(FILE_TOKEN,value,WriteTokenFileResult);}functionWriteTokenFileResult(err:any,data:any){if(err){console.log(err);returnfalse;}TOKEN=tempValue;ReadGist();//otherFSreadFileca

javascript - Webpack2 不理解我的 SASS 文件中的 @import 语句(How to compile SASS with webpack2?)

UsingWebpack2和sass-loader4.11webpack--configwebpack.config.js这是我的webpack.config.jsvarpath=require('path');varsass=require("./sass/lifeleveler.scss");module.exports={entry:'./dist/main.js',output:{filename:'lifeleveler.app.js',path:path.resolve(__dirname,'dist')},watch:true,watchOptions:{aggregat

javascript - react native : @providesModule declaration with the same name across two different files

我们有两个repos,它们都有react-native作为依赖项;一个是实际的RN应用程序,另一个是UI包,其中包含许多自定义的react-native组件。当我使用RN应用程序符号链接(symboliclink)(使用npm链接)UI包并尝试启动js服务器时,它抛出以下错误:此错误是由两个不同文件中具有相同名称的@providesModule声明引起的。这似乎是因为它在UI包的react-native副本中获取相同的RN文件。我知道watchman不使用符号链接(symboliclink)存在问题,但我认为这是不同的-与有两个react-native模块有关。请问有人知道解决这个问题

javascript - 模型或 Backbone.js View 中的类私有(private)属性

是否可以在模型中拥有私有(private)属性?就像(构造函数)函数中的局部声明变量一样,不附加到this,而是局部声明并且仅由(构造函数)函数中定义的任何内容可见。没有BBView的示例:functionMyView(aModel){var$internalInput=$('');this.render:function($where){$internalInput.val(aModel.get('SomeProperty'));$where.append($('').append($internalInput));};this.toggleReadonly:function(){t