草庐IT

jest-jasmine

全部标签

javascript - 如何在 Jest 中模拟导出的常量

我有一个依赖于导出的const变量的文件。此变量设置为true,但如果需要,可以手动将其设置为false,以防止在下游服务请求时出现某些行为。我不确定如何在Jest中模拟const变量,以便我可以更改它的值以测试true和false条件.例子://constantsmoduleexportconstENABLED=true;//allowThroughmoduleimport{ENABLED}from'./constants';exportfunctionallowThrough(data){return(data&&ENABLED===true)}//jesttestimport{a

javascript - 如何使用 Karma 和 Jasmine 在 Angular 服务中测试 'private' 函数

我的Angular应用程序中有一个看起来像这样的服务:angular.module('BracketService',[]).factory('BracketService',[function(){functioncompareByWeight(a,b){returna.weight-b.weight;}functionfilterWeightGroup(competitors,lowWeight,highWeight){//filterstuff}functioncreateBracketsByWeightGroup(weightGroup){//createsomebracket

javascript - 如何使用 Karma 和 Jasmine 在 Angular 服务中测试 'private' 函数

我的Angular应用程序中有一个看起来像这样的服务:angular.module('BracketService',[]).factory('BracketService',[function(){functioncompareByWeight(a,b){returna.weight-b.weight;}functionfilterWeightGroup(competitors,lowWeight,highWeight){//filterstuff}functioncreateBracketsByWeightGroup(weightGroup){//createsomebracket

javascript - 在 Jasmine 2.0 中测试 AngularJS promise

我一直在努力思考Jasmine2.0和AngularJS的promise。我知道:Jasmine2.0introducedthedonefunction替换旧的runs和waitsFor函数AngularJS$qpromiseswillnotresolveuntiladigestcycleistriggered如何使用Jasmine2.0中的新异步语法测试AngularJSpromises? 最佳答案 在调用promise.resolve()之后:调用$timeout.flush().这将强制执行摘要循环并传播promise解决方案

javascript - 在 Jasmine 2.0 中测试 AngularJS promise

我一直在努力思考Jasmine2.0和AngularJS的promise。我知道:Jasmine2.0introducedthedonefunction替换旧的runs和waitsFor函数AngularJS$qpromiseswillnotresolveuntiladigestcycleistriggered如何使用Jasmine2.0中的新异步语法测试AngularJSpromises? 最佳答案 在调用promise.resolve()之后:调用$timeout.flush().这将强制执行摘要循环并传播promise解决方案

javascript - Jasmine calls.length 和 callCount 未定义

我正在尝试使用Jasmine测试我的chrome扩展程序但我无法让calls.length和callCount按预期运行。两种情况都返回undefined。我已经包含了代码示例和规范。如果有帮助,这是其余代码:https://github.com/DruRly/kamikaze/tree/closeIdleTab如何重现:gitclonehttps://github.com/DruRly/kamikaze/tree/closeIdleTabcd神风敢死队打开SpecRunner.html规范/kamikazeSpec.jsdescribe("kamikaze",function(){d

javascript - Jasmine calls.length 和 callCount 未定义

我正在尝试使用Jasmine测试我的chrome扩展程序但我无法让calls.length和callCount按预期运行。两种情况都返回undefined。我已经包含了代码示例和规范。如果有帮助,这是其余代码:https://github.com/DruRly/kamikaze/tree/closeIdleTab如何重现:gitclonehttps://github.com/DruRly/kamikaze/tree/closeIdleTabcd神风敢死队打开SpecRunner.html规范/kamikazeSpec.jsdescribe("kamikaze",function(){d

javascript - Jest 等同于 RSpec 惰性评估变量 (let)?

在rspec中你可以这样做:let(:input){'foo'}before_eachdosetup_some_thing(input)endcontext'wheninputisbardolet(:input){'bar'}it'doessomethingdifferent'doendendcontext'wheninputisbazdolet(:input){'baz'}it'doessomethingelsedifferent'doendend这允许您将大型对象的方法调用或实例化定义为其较小部分的总和。然后,您可以在不同的上下文中覆盖那些单独的小部分。这个想法是您在每次测试之前创

javascript - Jest 等同于 RSpec 惰性评估变量 (let)?

在rspec中你可以这样做:let(:input){'foo'}before_eachdosetup_some_thing(input)endcontext'wheninputisbardolet(:input){'bar'}it'doessomethingdifferent'doendendcontext'wheninputisbazdolet(:input){'baz'}it'doessomethingelsedifferent'doendend这允许您将大型对象的方法调用或实例化定义为其较小部分的总和。然后,您可以在不同的上下文中覆盖那些单独的小部分。这个想法是您在每次测试之前创

javascript - 使用 Jest 测试 React Component 函数

原创首先,我关注Flux架构。我有一个显示秒数的指示器,例如:30秒。每过一秒它就会少显示1秒,所以29、28、27直到0。当到达0时,我清除间隔以使其停止重复。此外,我触发了一个Action。发送此操作时,我的商店会通知我。所以当发生这种情况时,我将间隔重置为30秒,依此类推。组件看起来像:varIndicator=React.createClass({mixins:[SetIntervalMixin],getInitialState:function(){return{elapsed:this.props.rate};},getDefaultProps:function(){ret