我试图Mailer用jest 模拟一个类,我无法弄清楚如何去做.文档没有提供很多关于它如何工作的例子.过程是我将password-reset触发一个节点事件,当该事件被触发时,我想使用发送电子邮件Mailer.send(to, subject, body).这是我的目录结构:
project_root
-- __test__
---- server
------ services
-------- emails
---------- mailer.test.js
-- server
---- services
------ emails
-------- mailer.js
-------- __mocks__
---------- mailer.js
Run Code Online (Sandbox Code Playgroud)
这是我的模拟文件__mocks__/mailer.js:
const Mailer = jest.genMockFromModule('Mailer');
function send(to, subject, body) {
return { to, subject, body };
}
module.exports = Mailer;
Run Code Online (Sandbox Code Playgroud)
和我的 mailer.test.js
const EventEmitter = require('events');
const Mailer = jest.mock('../../../../server/services/emails/mailer');
test('sends an email when the password-reset event is fired', () => {
const send = …Run Code Online (Sandbox Code Playgroud) 我有一个数组变量$screenshots,我试图传递给我的Laravel视图.通常,我会使用@foreach和循环遍历数组,但我想通过将其定义为prop来将完整数组传递给Vue组件.我想这样做,以便我可以遍历组件中的数组.我收到了htmlentities() expects parameter 1 to be string, array given错误.
用VueJS和Laravel做这个的正确方法是什么?
这是我的刀片模板:
@section('content')
<ticket-edit id="edit-ticket" single-ticket="{{ $ticket }}" screenshots="{{ $files }}">
</ticket-edit>
@endsection
Run Code Online (Sandbox Code Playgroud)
这是我的自定义组件(不同的文件):
<script>
export default {
template: '#edit-ticket-template',
props: ['SingleTicket', 'screenshots'],
data: function() {
return {
ticket: [],
screenshots: []
};
},
methods: {
getTicket() {
return this.ticket = JSON.parse(this.SingleTicket);
},
getScreenshots() {
return this.screenshots = JSON.parse(this.files);
},
createNotes: function () {
var ticketNotes = $('.summernote');
ticketNotes.summernote({
height: 260,
toolbar: [
['style', ['bold', …Run Code Online (Sandbox Code Playgroud) 我正在使用Laravel并尝试学习Vue.js. 我有一个正常工作的删除请求,并从数据库中删除该对象.问题是在成功删除后没有从DOM中删除它.我正在使用该$remove方法并将其传递给完整的对象,所以我知道我错过了一些东西.
作为旁注,我有一个main.js作为组件的入口点PersonTable.vue.在PersonTable.vue持有该模板的模板和脚本.
这是我的Laravel视图:
<div id="app">
<person-table list="{{ $persons }}">
</person-table>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我的`PersonTable.vue:
<template id="persons-template">
<div class="container">
<div class="row">
<div class="col-sm-12">
<h1>Persons List</h1>
<table class="table table-hover table-striped">
<thead>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Email</td>
<td>Gender</td>
</tr>
</thead>
<tbody>
<tr v-for="person in list">
<td>{{person.first_name }}</td>
<td>{{person.last_name }}</td>
<td>{{person.email }}</td>
<td>{{person.gender }}</td>
<td><span @click="deletePerson(person)">X</span>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script>
export default {
template: '#persons-template',
props: ['list'],
methods: {
deletePerson: function(person) …Run Code Online (Sandbox Code Playgroud) 我有一个非常小的应用程序,有一个捐赠表格.表单引导用户完成填写信息的步骤.我有一个主要组件,它是表单包装器和主Vue实例,它包含所有表单数据(模型).所有子组件都是捐赠过程中的步骤.每个子组件都有要填写的输入字段,这些字段将更新父模型,以便在提交表单时我拥有父模型中的所有表单数据.以下是组件的组合方式:
<donation-form></donation-form> // Main/Parent component
Run Code Online (Sandbox Code Playgroud)
donation-form组件内部 :
<template>
<form action="/" id="give">
<div id="inner-form-wrapper" :class="sliderClass">
<step1></step1>
<step2></step2>
<step3></step3>
</div>
<nav-buttons></nav-buttons>
</form>
</template>
Run Code Online (Sandbox Code Playgroud)
现在,我正在设置每个子组件中输入的数据,然后我有一个watch方法正在监视要更新的字段,然后我$root通过执行此操作将它们推送到...
watch: {
amount() {
this.$root.donation.amount = this.amount;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是我的一个步骤我有很多字段,而且我似乎在编写一些重复的代码.此外,我确信这不是最好的方法.
我尝试将数据作为一个传递prop给我的子组件,但似乎我无法更改子组件中的道具.
除了将监视添加到子组件中的每个值之外,更新根实例甚至父实例的更好方法是什么?
更多示例
这是我的step2.vue文件 - step2 vue文件
这是我的donation-form.vue文件 - 捐赠形式的vue文件
我将如何设计类似于react-datepicker样式组件的样式?datepicker库看起来像是使用某种类型的BEM样式(下面的截图),我通常会使用它们提供的类名称并使用Sass来设置样式.但是,我如何使用样式组件来定位这些类名?这甚至可能吗?
我有一个Vue组件,requires一个文件是Vue mixin.所需的文件是供应商包的一部分,因此我无法修改该文件.我需要notifications从mixin 获得道具.最终结果是我将访问该notifications对象并获取读取通知量,以便将此计数显示为计算属性.似乎使用this.notifications不起作用.我怎样才能做到这一点?
这是我的组件:
var base = require('notifications/notifications');
Vue.component('spark-notifications', {
mixins: [base],
});
Run Code Online (Sandbox Code Playgroud)
这是notifications上一个组件中所需的文件:
module.exports = {
props: ['notifications', 'hasUnreadAnnouncements', 'loadingNotifications'],
/**
* The component's data.
*/
data() {
return {
showingNotifications: true,
showingAnnouncements: false
}
},
methods: {
/**
* Show the user notifications.
*/
showNotifications() {
this.showingNotifications = true;
this.showingAnnouncements = false;
},
/**
* Show the product announcements.
*/
showAnnouncements() {
this.showingNotifications = false;
this.showingAnnouncements = true; …Run Code Online (Sandbox Code Playgroud) 好的,坚持我在这里.我有一个我需要遵循的过程,并且有很多if语句我已经分解成较小的类而不是一个丑陋的开关或if/else语句.基本上,我调用类的handle方法,它确定我们在进程中的位置,实例化适当的类,然后构建所需的集合并返回它.
我有一个模型,我试图获得该nextAction特定记录.在nextAction将有一个名称,日期,timeRemaining和路由键返回集合.这是我的FreeLook.php模型中的方法:
public function nextAction()
{
// handle basically just calls a handle method on the NextActionHandler class.
return handle(new NextActionHandler($this));
}
Run Code Online (Sandbox Code Playgroud)
该NextActionHandler课程列出了我们在这个过程中的位置.它通过使用我创建的特征来实现Actionable.这是NextActionHandler班级:
class NextActionHandler
{
use Actionable;
protected $freeLook;
public function __construct($freeLook)
{
$this->freeLook = $freeLook;
}
public function handle()
{
switch (true) {
case $this->wantsSign() && !$this->signJobIsComplete():
return handle(new SignNextAction($this->freeLook));
case $this->wantsPaint() && !$this->paintJobIsComplete():
return handle(new PaintNextAction($this->freeLook));
case $this->needsToSubmitCoOp():
return handle(new CoOpNextAction($this->freeLook));
default:
return handle(new DefaultNextAction($this->freeLook));
}
} …Run Code Online (Sandbox Code Playgroud) 我正在尝试解决HackerRank中的问题,我的提交有问题.我的代码在PyCharm中工作,但HackerRank不接受我的提交.
以下是我要解决的问题:https://www.hackerrank.com/challenges/staircase
这是我的代码:
def staircase(num_stairs):
n = num_stairs - 1
for stairs in range(num_stairs):
print ' ' * n, '#' * stairs
n -= 1
print '#' * num_stairs
staircase(12)
Run Code Online (Sandbox Code Playgroud)
任何想法为什么HackerRank没有接受我的答案?
我有一个todos的实时模板,当我创建它时,我想要一个下拉列表,它给了我"todo","fixme"和"note"的选项.我知道我可以使用enum它,但我似乎无法让它正常工作.这是我的实时模板的屏幕截图:
以下是使用该实时模板的GIF:
我究竟做错了什么?
我对编码很新,我需要一些代码的帮助.这是我的问题:我想在Google电子表格中获取许多数据单元并通过电子邮件发送.我想出了如何将数据拉入电子邮件并且电子邮件发送,但是,数据仅用逗号分隔,很难区分.如何让每个单元格的数据显示在电子邮件的单独行中?我相信我可以用数组做到这一点,但正如我所说的,我是新手,我无法弄清楚到目前为止我怎么做.如果你能提供一个解释,那将非常感激 - 希望这将使我不再问同样的问题并教我.感谢您的耐心和帮助!
function emailData() {
//Gather data from "Responses" sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var responses = ss.getSheetByName("Form Responses");
var lastRow = responses.getLastRow();
var data = responses.getRange("A"+(lastRow)+":AK"+(lastRow));
var values = data.getValues();
//Gather email addresses from "Email" sheet (I have not gotten this far yet)
var email = ss.getSheetByName("Email");
var startRow = 2;
var emailAdress = "email@email.com";
var subject = "Capacity Campaign Contact Form";
MailApp.sendEmail(emailAdress,subject,values);
}
Run Code Online (Sandbox Code Playgroud) 我正在搞乱一些简单的练习,发现了一些我觉得很奇怪的东西.我写了一个非常简单的HTML表单,当用户输入他们的名字时,如果是,Bob或者Alice它们会很棒.如果它是另一个名字,它会说,I don't know you.所以,我的想法是使用逻辑运算符来比较输入的用户名.这是我的代码:
<h1>This is the practice space</h1>
<div id="output">
<label>what is your name?</label>
<input id="name" type="text">
<button type="button" onclick="getName()">Send it through!</button>
<span id="output-name"></span>
</div>
<script>
function getName(){
var userName = document.getElementById('name').value;
if(userName === 'Alice' || 'Bob'){
document.getElementById('output-name').innerHTML = 'Hello ' + userName + '! Glad to have you!';
} else {
document.getElementById('output-name').innerHTML = 'I don\'t know you.';
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
对我来说这说"如果userName等于Alice,那么就是真的,如果没有,如果userName等于Bob那么真的.如果没有,那就I don't know …
我正在使用模型来查询远程MySQL数据库,当我运行查询时,Laravel正在尝试连接到我需要连接的表的复数版本.表的名称是activity,我得到的错误是:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'health.activities' doesn't exist (SQL: select * from `activities`)
Run Code Online (Sandbox Code Playgroud)
我刚为这个使用了这个模型,artisan make:model Activity所以我不知道发生了什么.这是我的模型:
<?php
namespace App;
use DB;
use Role;
use Illuminate\Database\Eloquent\Model;
class Activity extends Model
{
private $activity;
function __construct()
{
$this->activity = DB::connection('mysql_remote')->table('activity');
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
public function getDashboard()
{
$data = [
'page_title' => 'Dashboard',
'users' => User::getUser(),
'test' => Activity::get(),
];
return view('dashboard.dashboard', $data);
}
Run Code Online (Sandbox Code Playgroud)
任何人都知道为什么会这样吗?
javascript ×5
vue.js ×4
laravel ×3
php ×2
jestjs ×1
mysql ×1
phpstorm ×1
python ×1
reactjs ×1
unit-testing ×1
vue-resource ×1