目前,我正在为我的项目实施单元测试,并且其中包含一个文件window.location.href
。
我想对此进行测试,这是我的示例代码:
it("method A should work correctly", () => {
const url = "http://dummy.com";
Object.defineProperty(window.location, "href", {
value: url,
writable: true
});
const data = {
id: "123",
name: null
};
window.location.href = url;
wrapper.vm.methodA(data);
expect(window.location.href).toEqual(url);
});
Run Code Online (Sandbox Code Playgroud)
但是我得到这个错误:
TypeError: Cannot redefine property: href
at Function.defineProperty (<anonymous>)
Run Code Online (Sandbox Code Playgroud)
我尝试了一些解决方案,但没有解决。我需要一些提示来帮助我摆脱困境。请帮助。
我需要对 window.location.assign 进行单元测试。但是当我运行测试时,我收到此错误。
Cannot spy the assign property because it is not a function; undefined given instead
这是我的代码:
jest.spyOn(window.location, "assign");
Run Code Online (Sandbox Code Playgroud)
有人能给我一些关于这个案例的提示或解决方案吗?
我正在编写一些单元测试,但我在使用具有inject
属性的组件时遇到了麻烦。
我正在使用shallowMount
. 我对此做了一些研究。并且有办法为provide
https://vue-test-utils.vuejs.org/api/options.html#provide创建假数据。但是,我没有看到任何有关inject
.
所以,我需要一些关于如何inject
在 Vuejs 中进行单元测试的建议?
在这个示例测试文件中,我看到了两种不同的语法
一个是const app = fixture.debugElement.componentInstance;
,另一个是const compiled = fixture.nativeElement;
我不知道这两种语法有什么不同?
我对角度测试完全陌生,我正在将它应用到我的项目中,但对此我有点困惑。
describe('AppComponent (initial CLI version)', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app');
}));
it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges(); …
Run Code Online (Sandbox Code Playgroud) 我正在将 Ivy 与 Angular Material 一起使用,但是当我运行时,我遇到ng build
了以下问题:
ERROR in Tried to overwrite D:/Subin/PROJECTS/angular-ivy-sample/node_modules/@angular/material/table/typings/table.d.ts.__ivy_ngcc_bak with an ngcc back up file, which is disallowed.
Run Code Online (Sandbox Code Playgroud)
有什么办法解决它吗?
我正在使用Angular 8.0.0和Angular 材料 8.0.1。
我找到了一些有用的链接,但似乎没有解决方案:
我遇到了错误,需要您的帮助。感谢您收看这个问题。
我的情况:我正在为我的项目配置Drone CI工具,当我在drone.yml上运行单元测试时得到了这个。
Validation Error:
Module <rootDir>/node_modules/vue-jest in the transform option was not found.
Configuration Documentation:
https://jestjs.io/docs/configuration.html
Run Code Online (Sandbox Code Playgroud)
这是我的 jest.conf.js
transform: {
"^.+\\.js$": "babel-jest",
".*\\.vue$": "<rootDir>/node_modules/vue-jest"
},
Run Code Online (Sandbox Code Playgroud)
我尝试过的
<rootDir>/node_modules/
。但是我又犯了一个错误Module vue-jest in the transform option was not found.
。所以我认为这不是正确的解决方案我正在研究 Nextjs 并尝试上传单个文件。每次附加新文件时,都会在控制台日志中收到此错误。
在控制台,我看到这个错误:
Warning: A component is changing an uncontrolled input of type file to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.
Run Code Online (Sandbox Code Playgroud)
然后,第二个是:
react-dom.development.js:2592 Uncaught DOMException: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
Run Code Online (Sandbox Code Playgroud)
这是我的示例代码:
Warning: A component …
Run Code Online (Sandbox Code Playgroud) 我正在为包含的文件实施单元测试,window.location.href
需要对其进行检查。
我开玩笑的版本是22.0.4
。在节点版本> = 10上运行测试时,一切都很好
但是我在运行它时收到此错误 v8.9.3
console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Not implemented: navigation (except hash changes)
Run Code Online (Sandbox Code Playgroud)
我对此一无所知。我在许多页面上进行了搜索,以找出解决方案或有关此问题的任何提示,以了解此处发生的情况。
[更新]-我对源代码进行了深入研究,我认为此错误来自jsdom。
at module.exports (webapp/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:9:17)
at navigateFetch (webapp/node_modules/jsdom/lib/jsdom/living/window/navigation.js:74:3)
Run Code Online (Sandbox Code Playgroud)
exports.evaluateJavaScriptURL = (window, urlRecord) => {
const urlString = whatwgURL.serializeURL(urlRecord);
const scriptSource = whatwgURL.percentDecode(Buffer.from(urlString)).toString();
if (window._runScripts === "dangerously") {
try {
return window.eval(scriptSource);
} catch (e) {
reportException(window, e, urlString);
}
}
return undefined;
};
exports.navigate = (window, newURL, flags) => {
// This is NOT a spec-compliant implementation of navigation in …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Cypress 和cypress-plugin-snapshots在我的页面上进行 e2e 测试的快照测试。
但我得到了这个错误TypeError: cy.document(...).toMatchSnapshot is not a function
。
这是我的配置:
插件/index.js
const { initPlugin } = require('cypress-plugin-snapshots/plugin');
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
initPlugin(on, config);
return config;
}
Run Code Online (Sandbox Code Playgroud)
支持/index.js
import 'cypress-plugin-snapshots/src/commands';
Run Code Online (Sandbox Code Playgroud)
赛普拉斯.json
{
"ignoreTestFiles": [
"**/__snapshots__/*",
"**/__image_snapshots__/*"
]
}
Run Code Online (Sandbox Code Playgroud)
home.spec.js
context('Querying', () => {
beforeEach(() => {
cy.server();
cy.fixture('user.json').as('userJSON');
cy.route('GET', 'users?id=*', '@userJSON').as('getUser');
cy.visit('http://localhost:4200/1');
})
it.only('LANDING - …
Run Code Online (Sandbox Code Playgroud) 当我尝试暂停或更新由 创建的声音对象的状态时Audio.Sound()
,出现错误指示声音未加载。
Error : Cannot complete operation because sound is not loaded.
我不明白,因为我从加载文件并播放它的同一对象调用了该方法。
这是我的代码:
import React, { useState, useEffect } from "react";
import { Feather } from "@expo/vector-icons";
import {
StyleSheet,
Text,
View,
Button,
FlatList,
TouchableOpacity,
Image
} from "react-native";
import { Audio } from "expo-av";
const imageLocation = "./../assets/bibliotheque";
const soundLocation = "./../sounds/bibliotheque";
export default BibliothequeScreen = ({ navigation }) => {
const [playing, setPlaying] = useState(false);
const [soundPlaying, setSoundPlaying] = useState(false);
const soundObject = new Audio.Sound(); …
Run Code Online (Sandbox Code Playgroud) 我有一个这样的html字符串,它来自API:
const response = `
<html>
<head>
<title></title>
</head>
<body>
<code>Value I want to get<br></code>
</body>
</html>
`;
Run Code Online (Sandbox Code Playgroud)
因此,内容可能是动态的,但标签<code>
是唯一的。我希望对此有更多解决方案,以了解最佳解决方案。
我正在创建一个非常大的 Angular 库。因为我有很多类和组件,所以我将它们结构化为层次结构。例如,我有:
在 中public_api.ts
,我有许多导出,每个component/module/service
我想在库上公开的导出都有一个,但这会扁平化我的层次结构。
我发现维护层次结构的唯一方法是为层次结构树上的每个组创建一个库。例如,面板库(Panels-lib)、图层库(Layers-lib)等,然后复制文件系统上的层次结构,将每个库放在单独的文件夹中:面板文件夹、图层文件夹ETC。
这样,在主应用程序中我可以通过这种方式导入组件:
import {ToolBar} from "MyMap/Panels/Panels-lib";
import {Line} from "MyMap/Geometries/Geometries-lib";
Run Code Online (Sandbox Code Playgroud)
有更好的方法来实现这一目标吗?先感谢您。
unit-testing ×5
vuejs2 ×5
angular ×4
jestjs ×4
angular-cli ×2
javascript ×2
reactjs ×2
vue.js ×2
angular7 ×1
angular8 ×1
audio ×1
babel-jest ×1
cypress ×1
e2e-testing ×1
expo ×1
frontend ×1
html ×1
jasmine ×1
next.js ×1
ng-packagr ×1
react-native ×1
testing ×1