我有依赖于类 A 的类 B。我想测试类 B 的方法,该方法在内部调用类 A 的方法。现在,我想通过模拟类 A 对类 B 的方法进行单元测试。
我的代码结构:
class A {
getSomething() {
return "Something";
}
}
class B {
constructor(objectOfClassA: A) {
this._objectOfClassA = objectOfClassA;
}
functionofClassBToTest() {
const returnValueFromClassA = this._objectOfClassA.getSomething();
return returnValueFromClassA;
}
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我已经尝试过:
import ....
import { mocked } from 'jest-mock';
jest.mock("./A", () => {
return {
A: jest.fn().mockImplementation(() => {
return {
getSomething: getSomethingMock
}
})
};
});
const getSomethingMock = jest.fn().mockImplementation(() => {
return "Mock value";
});
const …Run Code Online (Sandbox Code Playgroud) 我试图使用bluebird的map函数和内置的并发控制.
我想检索一个名称列表,然后为每个名称发出一些POST请求.例如,我想为每周的每一天提出每个名称的请求.但是,我需要限制并发POST请求的数量,因为预期的服务器具有速率限制.
function getNames() {
//Open mongodb connection
//Get collection and array of names
//return array of names in a promise
}
function createDatesArray() {
//Create an array of rates
//return array of dates in a promise
//Ex. return Promise.resolve(datesArray);
}
getNames().map(function (name) {
return createDatesArray().map(function (date) {
return requestData(date, name);
}, {concurrency: 5});
}).then(function () {
//do something
});
Run Code Online (Sandbox Code Playgroud)
这是使用bluebird并发的正确方法吗?
文档链接在这里是bluebird文档.
我必须在 PostgreSQL 中创建一个函数来显示作为参数传递的字符串的成对字符。
我的想法是循环遍历字符串的字符,就像我在 C 或 Java 或其他语言中那样,但我不知道如何单独访问一个字符,例如,str[i]作为str一个字符串,和i字符的位置。
我所说的“字符对”是指字符对位置中的字符:即字符串中位置模 2 = 0 的字符。如果输入参数是“String”,则函数显示的字符将为“t”(即位置2,从位置1开始),以及“i”(即位置4)、“g”(即位置6)。
什么是标准赛普拉斯方式等待"请等待"模式关闭?
很容易检查它是否存在,但是如果不使用cy.wait(ms),我怎样才能使赛普拉斯继续检查一段时间,看看该元素是否已从DOM中删除,或者不可见?
我是Electron的新手,在查找应用程序菜单的工作示例时遇到了问题.
尝试将" 快速启动"应用程序与" 电子文档" 的" 类:菜单"页面中的示例结合使用时,似乎没有任何事情发生 - 修改这些label值无效.
谷歌搜索提出了更多的问题比它解决的-比如,是否需要打包我的应用程序在应用程序菜单中进行变革,或者我需要将我main.js和package.json于$projectRoot/resources/app(如果有的话,我需要将它打包运行它) ?
有没有更好的方法来获得Electron ......?
当我在OSX上将我的应用程序添加到我的应用程序时,应用程序菜单有一个条目 - Electron有一个选项Quit:
const electron = require('electron');
var menu = electron.Menu.buildFromTemplate([
{
label: 'Electron',
submenu: [
{
label: 'Options',
click: function() {
alert('Test');
}
}
]
}
]);
electron.Menu.setApplicationMenu(menu);
Run Code Online (Sandbox Code Playgroud) 我是 React 的新手,我按照 Heroku 的指南使用Create-react-app来创建一个新的React应用程序。我想使用 Google API 通过 Google 的 OAuth2 对用户进行身份验证并获取刷新令牌,因此我按照 Google API 节点客户端上的指南安装了“googleapis”包,npm install googleapis --save但是在使用 导入 googleapis 后import {google} from 'googleapis',出现以下错误命中npm start:
Uncaught TypeError: Cannot convert undefined or null to object
at Function.getPrototypeOf (<anonymous>)
at ./node_modules/google-p12-pem/node_modules/pify/index.js.module.exports (index.js:75)
at Object../node_modules/google-p12-pem/build/src/index.js (index.js:6)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/gtoken/build/src/index.js (index.js:50)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap 8c14a9046e11e185076c:88)
at Object../node_modules/google-auth-library/build/src/auth/jwtclient.js (jwtclient.js:63)
at __webpack_require__ (bootstrap 8c14a9046e11e185076c:678)
at fn (bootstrap …Run Code Online (Sandbox Code Playgroud) 自定义事件没有在 Vue 2 中传播。Vue 3 中是否有变化,因为如以下示例所示,自定义事件看起来像在组件链中冒泡:
const Comp1 = {
template: `
<button @click="this.$emit('my-event')">click me</button>
`
}
const Comp2 = {
components: {
Comp1
},
template: `
<Comp1/>
`
}
const HelloVueApp = {
components: {
Comp2
},
methods: {
log() {
console.log("event handled");
}
}
}
Vue.createApp(HelloVueApp).mount('#hello-vue')Run Code Online (Sandbox Code Playgroud)
<script src="https://unpkg.com/vue@next"></script>
<div id="hello-vue" class="demo">
<Comp2 @my-event="log"/>
</div>Run Code Online (Sandbox Code Playgroud)
主进程打开与服务的连接,呈现器需要访问该服务.
这可能吗?
我试着声明global.thing和exports.thing,并且具有渲染器require('electron').remote.thing-在那里的东西是一个函数或标量-但没有运气.
NestJS 是否可以立即处理一些安全实践?如果没有,除了头盔之外,您还可以分享哪些建议来保护 NestJS 应用程序的安全?我在 NestJS 中间件文档中看到一个使用头盔依赖项的示例。
使用TypeORM时,SQL注入被覆盖?
我的第一个Rust生产的WASM正在产生以下错误,我不知道如何进行调试。
wasm-000650c2-23:340 Uncaught RuntimeError: memory access out of bounds
at dlmalloc::dlmalloc::Dlmalloc::free::h36961b6fbcc40c05 (wasm-function[23]:670)
at __rdl_dealloc (wasm-function[367]:8)
at __rust_dealloc (wasm-function[360]:7)
at alloc::alloc::dealloc::h90df92e1f727e726 (wasm-function[146]:100)
at <alloc::alloc::Global as core::alloc::Alloc>::dealloc::h7f22ab187c7f5835 (wasm-function[194]:84)
at <alloc::raw_vec::RawVec<T, A>>::dealloc_buffer::hdce29184552be976 (wasm-function[82]:231)
at <alloc::raw_vec::RawVec<T, A> as core::ops::drop::Drop>::drop::h3910dccc175e44e6 (wasm-function[269]:38)
at core::ptr::real_drop_in_place::hd26be2408c00ce9d (wasm-function[267]:38)
at core::ptr::real_drop_in_place::h6acb013dbd13c114 (wasm-function[241]:50)
at core::ptr::real_drop_in_place::hb270ba635548ab74 (wasm-function[69]:192)
Run Code Online (Sandbox Code Playgroud)
上下文:从TypeScript自定义元素调用的最新Chrome,Rust wasm-bindgen代码,在影子DOM中的画布上运行。呈现到画布上的数据来自HTML5 AudioBuffer。所有rust变量都在本地范围内。
如果文档中仅出现一个实例,则Web组件可以正常工作,但是如果再出现其他实例,则如上所述将转储堆栈跟踪。该代码运行没有任何其他问题。
我知道Chrome中存在突出的内存错误-这是它们的外观吗,还是有经验的锈/毛病开发人员可以告诉我这是否异常?
js-sys = "0.3.19"
wasm-bindgen = "0.2.42"
wee_alloc = { version = "0.4.2", optional = true }
[dependencies.web-sys]
version = "0.3.4"
Run Code Online (Sandbox Code Playgroud)
rust代码很小,仅将AudioBuffer的两个通道呈现到提供的HTMLCanvasElement:
#[wasm_bindgen]
pub fn render(
canvas: web_sys::HtmlCanvasElement,
audio_buffer: &web_sys::AudioBuffer,
stroke_style: …Run Code Online (Sandbox Code Playgroud) 我正在使用Nestjs (7.x) 和Fastify(带有@nestjs/platform-fastify)。我正在尝试在我的项目 ( ) 中安装Helmetfastify-helmet,但我无法弄清楚如何将其与 Nestjs 集成/配置。将其带上飞机的正确方法是什么?
这是我的 Nestjs 引导程序:
import { NestFactory } from '@nestjs/core';
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify';
import { MainModule } from './main.module';
import * as helmet from 'fastify-helmet';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(MainModule);
await app.listen(3000, 0.0.0.0);
}
bootstrap();
Run Code Online (Sandbox Code Playgroud) javascript ×5
node.js ×3
electron ×2
nestjs ×2
typescript ×2
bluebird ×1
concurrency ×1
cypress ×1
fastify ×1
google-api ×1
helmet.js ×1
jestjs ×1
postgresql ×1
promise ×1
reactjs ×1
rust ×1
security ×1
shadow-dom ×1
string ×1
testing ×1
ts-jest ×1
typeorm ×1
unit-testing ×1
vue.js ×1
vuejs3 ×1
wasm-bindgen ×1