我的 NestJs 应用程序中有一个简单的控制器。
@Post('/')
async create(@Body() createUserRequest: CreateUserRequest): Promise<User> {
return await this.userService.create(createUserRequest);
}
Run Code Online (Sandbox Code Playgroud)
我的目标是使用笑话来测试这个功能。正如您所看到的,控制器注入了一个UserService
. 所以我尝试在单元测试中模拟此服务。测试用例如下所示。
describe('User Controller', () => {
let userService: UserService;
let userController: UserController;
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [UserController],
providers: [UserService],
}).compile();
userService = module.get<UserService>(UserService);
userController = module.get<UserController>(UserController);
});
describe('create', () => {
it('should return a user', async () => {
const result = new User();
jest.spyOn(userService, 'create').mockImplementation(() => result);
expect(await userController.create(new CreateUserRequest())).toBe(result);
});
});
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,jest.spyOn
模拟发生的地方会产生错误。 …
我尝试要求perfect-scrollbar
对我的laravel javascript 进行jquery插件。所以我跑了
npm install perfect-scrollbar
Run Code Online (Sandbox Code Playgroud)
在我的Javascript文件的第1行(位于下方ressources/assets/javascript/material-dashboard/myfile.js
)中,我需要使用此尝试的插件
require('perfect-scrollbar');
Run Code Online (Sandbox Code Playgroud)
该myscript.js
需要的app.js
用require('./material-dashboard/myscript.js')
现在浏览器控制台告诉我
Uncaught TypeError: $(...).perfectScrollbar is not a function
Run Code Online (Sandbox Code Playgroud)
资产与
npm run dev
Run Code Online (Sandbox Code Playgroud)
内容 myscript.js
require('perfect-scrollbar');
(function() {
isWindows = navigator.platform.indexOf('Win') > -1 ? true : false;
if (isWindows) {
// if we are on windows OS we activate the perfectScrollbar function
$('.sidebar .sidebar-wrapper, .main-panel').perfectScrollbar();
$('html').addClass('perfect-scrollbar-on');
} else {
$('html').addClass('perfect-scrollbar-off');
}
})();
Run Code Online (Sandbox Code Playgroud)
怎么了?
谢谢你的帮助!
我正在尝试为我的数据库编写一些日志过程。我用以下语句创建一个过程:
create procedure prc_wirte_log (
in p_schema varchar(255),
in p_item varchar(255),
in p_message varchar(255)
)
begin
insert into weather.log (`schema`, item, message) values (p_schema, p_item, p_message);
end;
Run Code Online (Sandbox Code Playgroud)
我得到错误 Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 7 0.063 sec
为什么?MySQL Workbench的意思是Incomplet Statment: excepting ;
在插入查询之后。
我能做什么?
我定义了两条资源路由。
Route::resource('p/contacts', 'BaseData\PrivateContactsController');
Route::resource('b/contacts', 'BaseData\ContactController');
Run Code Online (Sandbox Code Playgroud)
我的问题是两个资源组的前缀相同(contacts.show
,contacts.edit
...)
在Laravel 文档中,我找到了这种命名路线的方法
Route::resource('photos', 'PhotoController')->names([
'create' => 'photos.build'
]);
Run Code Online (Sandbox Code Playgroud)
在我看来,这种方式非常复杂,因为我必须为每个路由设置前缀。有没有更好的方法来为组的所有路由设置前缀?
我在我的角度分量中有一个像这样定义的可观察量。
profiles$!: Observable<Profile[] | undefined>;`
Run Code Online (Sandbox Code Playgroud)
我尝试像这样检查模板中该数组的长度。
<div *ngIf="(profiles$ | async).length > 0"></div>
Run Code Online (Sandbox Code Playgroud)
Object is possibly 'null' or 'undefined'.
通过这个构造,我从打字稿编译器得到了错误消息,这完全没问题。因此,向我的 if 条件添加一个空检查。
<div *ngIf="(profiles$ | async) && (profiles$ | async).length > 0"></div>
Run Code Online (Sandbox Code Playgroud)
我仍然收到相同的错误,该对象可能为空。我猜编译器无法识别空检查。我的问题是如何进行空检查以避免打字稿编译器出现错误。
有没有办法从带有频道 ID 的频道中获取关注者列表?我找到了这个片段,但它仅用于订阅者计数。
https://www.googleapis.com/youtube/v3/channels?part=statistics&id=<channel_id>&key=<api_key>
Run Code Online (Sandbox Code Playgroud)
有没有人有这方面的经验?
问候
我正在构建一个 nuxtjs 应用程序并尝试从全局中间件设置 cookie。我在 GitHub 上找到了这个贡献,它展示了一种方法来做到这一点。
所以我像这样实现了我的中间件
export default function ({ isServer, res, query }) {
if (query.lang) {
if (isServer) {
res.setHeader("Set Cookie", [`lang=${query.lang}`]);
} else {
document.cookie = `lang=${query.lang}`;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我使用?lang=xxx
作为参数访问我的应用程序时,我总是遇到 if 条件的 else 块。所以我得到了错误
document is not defined
Run Code Online (Sandbox Code Playgroud)
有谁知道我的代码有什么问题。我看不出与 github 上发布的代码有何不同。
我正在尝试使用 jenkins 和SSH Pipeline Steps插件运行 ssh 部署。我在 MacOS 上使用 openssh 创建了一个 ssh 密钥。
ssh-keygen -m PEM
Run Code Online (Sandbox Code Playgroud)
然后我使用ssh-copy-id
. 使用我的命令行登录效果很好。在 Jenkins 中,我创建了一个新的秘密。
我的管道步骤看起来像这样
stage("Deploy to docker host") {
steps {
script {
withCredentials([sshUserPrivateKey(
credentialsId: "docker-jenkins",
keyFileVariable: 'sshKey',
usernameVariable: 'sshUser'
)]) {
def remote = [:];
remote.name = 'docker-host';
remote.host = '127.0.0.1';
remote.user = sshUser;
remote.identity = sshKey;
remote.allowAnyHosts = true;
sshCommand remote: remote, command: "ls -lrt"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行管道时,我得到以下输出。
Executing command on 01-de.docker[127.0.0.1]: ls -lrt sudo: …
Run Code Online (Sandbox Code Playgroud) 我正在写一个sql语句。看起来像这样
select case when c.used = 1 then 'Used'
else 'Unused'
end
from my_table
Run Code Online (Sandbox Code Playgroud)
如何使用as
关键字命名 col 。我在字符串之后和end
. 什么都行不通。
请帮我。谢谢 :)
我在 gmt 区域的数据库中有一个时间戳。如何根据用户时区显示时间?目前我有这样的时间
return luxon.DateTime.fromSQL(created_at).setZone('local');
Run Code Online (Sandbox Code Playgroud)
它返回 gtm 中的时间。
我正在尝试为 Laravel 自定义我的电子邮件模板。所以我发布了通知和邮件供应商。
在resources/views/vendor/notifications/email.blade.php
文件中框架调用这样的组件
@component('mail::button')
Run Code Online (Sandbox Code Playgroud)
前缀代表什么mail::
?
我尝试在 下编写自己的组件locatete resources/views/vendor/mail/mycomponent.blade.php
。所以我也将其称为默认组件。
@component('mail::mycomponent')
Run Code Online (Sandbox Code Playgroud)
这是行不通的。这里的错误:
View [mycomponent] not found. (View: /resources/views/vendor/notifications/email.blade.php)
Run Code Online (Sandbox Code Playgroud)
所以我的问题是前缀mail::
点在哪里?我可以将它用于我自己的组件吗?
我正在尝试在我的 docker 映像中安装 mongodb php 驱动程序。
缩短的 Dockerfile:
FROM php:7.2-fpm
RUN pecl install mongodb
RUN echo "extension=mongo.so" > $PHP_INI_DIR/conf.d/mongo.ini
Run Code Online (Sandbox Code Playgroud)
后来在我的 Dockerfile 中,我尝试根据 mongodb 扩展安装一个 Composer 应用程序。我得到这个错误:
PHP Warning: PHP Startup: Unable to load dynamic library 'mongo.so' (tried: /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongo.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongo.so:
cannot open shared object file: No such file or directory), /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongo.so.so (/usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongo.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Run Code Online (Sandbox Code Playgroud) laravel ×4
javascript ×3
php ×3
laravel-5 ×2
sql ×2
typescript ×2
angular ×1
api ×1
cookies ×1
database ×1
docker ×1
dockerfile ×1
email ×1
java ×1
jenkins ×1
jestjs ×1
laravel-5.7 ×1
laravel-mail ×1
laravel-mix ×1
luxon ×1
mariadb ×1
mongodb ×1
mysql ×1
nestjs ×1
nuxt.js ×1
plsql ×1
procedure ×1
rxjs ×1
ssh ×1
unit-testing ×1
youtube ×1
youtube-api ×1