我有一个依赖于导出const变量的文件.此变量设置为true但如果需要,可以false手动设置以防止下游服务请求它时的某些行为.
我不知道如何const在Jest中模拟变量,以便我可以更改它的值来测试true和false条件.
例:
//constants module
export const ENABLED = true;
//allowThrough module
import { ENABLED } from './constants';
export function allowThrough(data) {
return (data && ENABLED === true)
}
// jest test
import { allowThrough } from './allowThrough';
import { ENABLED } from './constants';
describe('allowThrough', () => {
test('success', () => {
expect(ENABLED).toBE(true);
expect(allowThrough({value: 1})).toBe(true);
});
test('fail, ENABLED === false', () => {
//how do I override the …Run Code Online (Sandbox Code Playgroud) 我有一个表单,其中包含2个复选框和2个禁用的输入文本字段.
如果仅选中第一个复选框,则应启用以下输入文本字段:
如果仅选中第二个复选框,则应启用以下输入文本字段:
如果同时选中了两个复选框,则应启用所有输入文本字段.我遇到的问题是,如果选中了两个复选框,则取消选中一个复选框,将禁用2个电子邮件文本字段.
这是我所拥有的一个小提琴.我可以使用jQuery. http://jsfiddle.net/Ujxkq/
这是我的HTML:
<form id="myForm">
<h3>Section 1</h3>
Checkbox 1: <input type="checkbox" name="checkbox1" id="checkboxOne" onclick="enableDisableEmail(this.checked, 'emailAddr', 'emailConfirm');enableDisableSection1(this.checked, 'fullName');" />
<p><input type="text" id="emailAddr" name="myEmailAddr" placeholder="Email" disabled /></p>
<p><input type="text" id="emailConfirm" name="myEmailConfirm" placeholder="Confirm Email" disabled /></p>
<p><input type="text" id="fullName" name="myFullName" placeholder="Full Name" disabled /></p>
<h3>Section 2</h3>
Checkbox 2: <input type="checkbox" name="checkbox2" id="checkboxTwo" onclick="enableDisableEmail(this.checked, 'emailAddr', 'emailConfirm');enableDisableSection2(this.checked, 'color', 'size', 'model');" />
<p><input type="text" id="color" name="myColor" placeholder="Color" disabled /></p>
<p><input type="text" id="size" name="mySize" placeholder="Size" …Run Code Online (Sandbox Code Playgroud) 我正在尝试根据本教程配置webpack 并继续得到相同的错误.我在调试这两条消息时遇到问题:
ERROR in ./app.js
Module parse failed: /path/react/react-webpack-babel/app/app.js Line 1: Unexpected reserved word
You may need an appropriate loader to handle this file type.
| import React from "react";
| import Greeting from "./greeting";
|
ERROR in ./index.html
Module parse failed: /path/react/react-webpack-babel/app/index.html Line 1: Unexpected token <
You may need an appropriate loader to handle this file type.
| <!DOCTYPE html>
| <html>
|
Run Code Online (Sandbox Code Playgroud)
这是我的webpack.configure.js
module.exports = {
context: __dirname + '/app',
entry: {
javascript: "./app.js", …Run Code Online (Sandbox Code Playgroud) 是否可以使用CSS使内容容器的左右边缘看起来像这个图像?如果可能的话,我一直试图找出一种不使用图像的方法.

这是我一直在努力的jsFiddle."顶级"类的CSS永远不会被应用."底层"类的CSS似乎工作正常.
HTML:
<div class="drop-shadow top bottom">
Content here.
</div>
Run Code Online (Sandbox Code Playgroud)
CSS:
.drop-shadow {
/** Create container. Box-shadow here is to color the inside of the container **/
position:relative;
width:50%;
background: none repeat scroll 0 0 #FFFFFF;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 40px rgba(0, 0, 0, 0.1) inset;
padding:3em;
margin: 2em 20px 4em;
text-align:center
}
.top:before,
.top:after {
/** Generate pseudo-elements ('before' and 'after') and push them behind the container box. Position pseudo-elements ('before', and …Run Code Online (Sandbox Code Playgroud) 如何为GraphQL中的字符串数组创建对象属性的模式?我希望响应看起来像这样:
{
name: "colors",
keys: ["red", "blue"]
}
Run Code Online (Sandbox Code Playgroud)
这是我的架构
var keysType = new graphql.GraphQLObjectType({
name: 'keys',
fields: function() {
key: { type: graphql.GraphQLString }
}
});
var ColorType = new graphql.GraphQLObjectType({
name: 'colors',
fields: function() {
return {
name: { type: graphql.GraphQLString },
keys: { type: new graphql.GraphQLList(keysType)
};
}
});
Run Code Online (Sandbox Code Playgroud)
当我运行此查询时,我得到一个错误,没有数据,错误就是 [{}]
查询{colors {name,keys}}
但是,当我运行查询只返回名称时,我得到了成功的响应.
查询{colors {name}}
如何在查询密钥时创建一个返回字符串数组的模式?
我使用的是漂亮的标准,因为该项目使用的标准是棉绒。
在更漂亮的pre-commit钩子示例之后,我正在更漂亮的提交上运行。但是我想忽略package.json文件。我尝试添加package.json到.prettierignore文件,但这没有用。
我在package.json中使用的更漂亮的预提交钩子示例中的代码
{
"scripts": {
"precommit": "lint-staged"
},
"lint-staged": {
"*.{js,json,css}": [
"prettier --write",
"git add"
]
}
}
Run Code Online (Sandbox Code Playgroud)
```
我一直在尝试学习如何在 xslt 中进行编码,目前仍停留在如何使用 xsl:apply-templates 标记周围的条件测试上。
这是我正在测试的 xml。
<?xml version="1.0" encoding="utf-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
Run Code Online (Sandbox Code Playgroud)
这是我的xslt
<xsl:template match="/">
<xsl:apply-templates select="catalog/cd" />
</xsl:template>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="artist" />
<br />
<xsl:apply-templates select="country" />
<br />
<xsl:if test="country != 'USA' and year != '1985'">
<xsl:apply-templates select="year" />
</xsl:if>
</p>
</xsl:template>
<xsl:template match="artist">
<xsl:value-of …Run Code Online (Sandbox Code Playgroud) 是否可以设置<select>菜单的样式,如下图所示:

这是一个小提琴,我一直在努力,但无法正确的箭头.
这是HTML:
<select>
<option>Alabama</option>
<option>Alaska</option>
</select>
Run Code Online (Sandbox Code Playgroud)
这是CSS:
select {
background: -webkit-linear-gradient(#C9C9C9, #CCC);
background: -moz-linear-gradient(#C9C9C9, #CCC);
border: 1px solid #ccc;
color: white;
text-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
padding:10px;
}
Run Code Online (Sandbox Code Playgroud)
是否可以像这样设置<select>菜单的样式?
我一直在尝试裁剪屏幕宽度小于768像素的图像。图像应从左侧和右侧均匀裁剪。
这是全尺寸图片的示例(图片尺寸为900px宽x 250px高。:

这是我试图在屏幕尺寸小于768p宽时创建的裁剪版本。在此版本中,图片的宽度为320px,但应以768px开始裁剪:

这是到目前为止我一直在使用的HTML:
<div class="container">
<div class="image-container">
<img src="http://i.imgur.com/H7cpsLK.jpg" />
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是CSS:
.container {
width: 1280px;
max-width: 100%;
min-width: 768px;
}
.image-container {
width:100%;
}
img {
max-width:100%;
height:auto;
}
@media only screen and (max-width:768px) {
.image-container {max-width:768px; overflow:hidden;}
}
Run Code Online (Sandbox Code Playgroud)
这是我一直在尝试创建的小提琴:http : //jsfiddle.net/QRLTd/
是否可以同时从左右两侧裁剪图像?
我有一个以UTC时间存储的字符串.我想看看这个时间是否在当前的UTC时间之后.我使用的是momentjs,当只有1小时的差异时,isAfter()方法返回不正确的值.
active_time变量发生在15:00 utc.current_time设置为16:00 utc.所以我认为active_time.isAfter(current_time)应该回来,false但它正在回归true.我怎样才能让它回归false?
jsFiddle链接:http://jsfiddle.net/Ln1bz1nx/
码:
//String is already in utc time
var active_time = moment('2015-06-04T15:00Z', 'YYYY-MM-DD[T]HH:mm[Z]');
//Convert current time to moment object with utc time
var current_time = moment( moment('2015-06-04T16:00Z').utc().format('YYYY-MM-DD[T]HH:mm[Z]') );
console.log('active_time =',active_time);
console.log('current_time =',current_time);
console.log( active_time.isAfter(current_time) ); //Why does this return true?
Run Code Online (Sandbox Code Playgroud)