草庐IT

DATA_TYPE_TEST

全部标签

javascript - 如何在 Vue.js 中测试计算属性?无法模拟 "data"

我想知道如何在Vue.js的单元测试中测试计算属性。我已经通过vue-cli(基于webpack)创建了一个新项目。例如这是我的组件:exportdefault{data(){return{source:[]}},methods:{removeDuplicates(arr){return[...newSet(arr)]}},computed:{types(){returnthis.removeDuplicates(this.source))}}}我试过这样测试it('shouldremoveduplicatesfromarray',()=>{constarr=[1,2,1,2,3]co

javascript - meteor JS : How to stub validated method in unit test

我正在使用经过验证的方法(mdg:validated-method)和LoggedInMixin(tunifight:loggedin-mixin)。现在我的单元测试出现了问题,因为它们因notLogged错误而失败,因为在单元测试中当然没有登录用户。我怎么必须stub呢?方法constresetEdit=newValidatedMethod({name:'reset',mixins:[LoggedInMixin],checkLoggedInError:{error:'notLogged'},//单元测试describe('resetEdit',()=>{it('shouldreset

javascript - typescript 键盘事件 : argument of type 'Event' is not assignable to parameter of type 'KeyboardEvent'

即使代码运行完美,我也会出现以下错误:"TS2345:Argumentoftype'Event'isnotassignabletoparameteroftype'KeyboardEvent'.Property'altKey'ismissingintype'Event'."//InaClasspubliclistenTo=(window:Window)=>{['keydown','keyup'].forEach(eventName=>{window.addEventListener(eventName,e=>{this.handleEvent(e);//{const{key}=event

javascript - click.modal.data-api 作为事件名称是什么意思?

这个问题在这里已经有了答案:Whatis.divClickedhere?(3个答案)关闭9年前。我正在通读BootstrapsJavaScript并注意到以下代码:$(document).on('click.modal.data-api','[data-toggle="modal"]',function(e){//dosomething});谁能给我解释一下为什么是"click.modal.data-api"。事件后的点是做什么的?也许我是盲人,但我似乎找不到任何关于此的文档。

javascript - 在 Angular2 中构建 multipart/form-data POST 请求并验证输入类型文件

我有一张图片(base64),需要通过POST请求发送(并等待响应)。POST请求需要是Content-Type:multipart/form-data。图片需要是Content-Type:image/jpgPOST请求应该是这样的:POSThttps://www.url...HTTP/1.1Content-Type:multipart/form-data;boundary=-------------------------acebdf13572468User-Agent:FiddlerHost:www.host.comContent-Length:199640------------

javascript - 带有异步 forEach 循环的磁带 "test exited without ending"错误

我在做什么编辑:我创建了一个repo使用我的问题的简化版本重现问题。我正在尝试使用browserstack设置自动化前端测试,selenium-webdriver和tape.Moreabouttape这个想法是定义多个浏览器和设备,这些浏览器和设备必须用X数量的给定测试一个接一个地进行测试。在下面的例子中,我在OSX上只定义了一个测试和两个浏览器。为了只定义一次浏览器并处理测试,我创建了一个repotest-runner,它应该作为dev-dependency添加到需要的repos在给定的设备和浏览器上测试。test-runner使所有需要的测试都通过,启动第一个浏览器,在该浏览器上运

javascript - npm run build 失败并显示 "Error: custom keyword definition is invalid: data.errors should be boolean"

当我尝试构建VueJS应用程序时,我发现npm出错。我在GitLabCI的build阶段看到这个错误。我找不到任何关于错误消息的提及。我以前能够成功运行npmrunbuild并且我没有对Vue应用程序代码进行任何更改,所以我不确定是什么导致了这个错误。-Buildingforproduction...ERRORError:customkeyworddefinitionisinvalid:data.errorsshouldbebooleanError:customkeyworddefinitionisinvalid:data.errorsshouldbebooleanatAjv.addK

javascript - 使用: and => for the return type with a TypeScript function?有什么区别

我有以下代码:///functionaddThemePrototypes(){vartemplateSetup=newArray();$.fn.addTemplateSetup=function(func,prioritary){if(prioritary){templateSetup.unshift(func);}else{templateSetup.push(func);}};}有人能告诉我为什么要用=>void来声明吗?interfaceJQuery{addTemplateSetup:(func:Function,priority:bool)=>void;}我想我对如何从java

javascript - 执行 Action 时 redux 出错 : Uncaught type error: cannot read property 'type' of undefined

刚刚接触React。我想这是一个基本问题,但我不明白为什么reducer没有被解雇或更新状态:我的HomeView.js:....const{localeChange,counter,locale}=this.propsreturn(increment(7)}>Increment.....)constmapStateToProps=(state)=>({locale:state.locale,counter:state.counter})exportdefaultconnect(mapStateToProps,{localeChange,increment})(HomeView)我的r

javascript - 未捕获的类型错误 : Failed to execute 'observe' on 'MutationObserver' : parameter 1 is not of type 'Node'

所以我下面的代码在jsfiddle中独立运行。但出于某种奇怪的原因..在将它推送到实时服务器后,我一直收到此错误:/我无法弄清楚为什么......错误:mycodewitherror.js:23UncaughtTypeError:Failedtoexecute'observe'on'MutationObserver':parameter1isnotoftype'Node'.js:$(document).ready(function(){//Thebelowcollectsuserloginname,newlogindateandtime,andprevioususeURLvarelem