Jest是否吞下console.log输出?
// __tests__/log.test.js
it('logs', () => {
console.log('hey') // expect to see "hey" printed in terminal
})
// terminal output
$ jest --forceExit
PASS __tests__/log.test.js
? logs (1ms) # where's "hey"?
Run Code Online (Sandbox Code Playgroud)
我关心的主要原因是我正在写一些异步beforeAll和afterAll东西,我想使用console.log语句来调试事件的顺序.
// index.js
type complexThing = {
a: string
}
type Thing = {
x: number,
y: boolean,
z: complexThing
}
export default {
x: 0,
y: true,
z: {a: 'hello'}
} : Thing // this says my default export is a Thing
Run Code Online (Sandbox Code Playgroud)
或者,我不介意内联键入每个对象属性,但我认为这在语法上是不可能的:
export default {
// I don't know how to add type signatures here
x: 0, // number
y: true, // boolean
z: {a: 'hello'} // complexThing
}
Run Code Online (Sandbox Code Playgroud)
我不希望做的是存储变量只是对流动键入:
// index.js
type …Run Code Online (Sandbox Code Playgroud) 有没有人用es2015语法编写茉莉/开玩笑测试?它需要多少垫/ /填充/分散?
我无法正确导入功能.我有一个模块: ..../utils/TweetUtils.js
'use strict';
export function getListOfTweetIds (tweets) {
return Object.keys(tweets);
};
Run Code Online (Sandbox Code Playgroud)
和一个测试套件:
... ./__测试__/TweetUtils-test.js
'use strict';
jest.dontMock('../TweetUtils');
import * as TweetUtils from '../TweetUtils';
describe('Tweet utilities module', () => {
it('has access to the TweetUtils methods', () => {
let testObj = {a:'a',b:'b',c:'c'};
// Passes
expect(TweetUtils.getListOfTweetIds).toBeDefined();
// Passes
expect(typeof TweetUtils.getListOfTweetIds).toBe('function');
// Fails
expect(TweetUtils.getListOfTweetIds(testObj)).toBeTruthy();
});
});
Run Code Online (Sandbox Code Playgroud)
如果我用这样的东西破解控制台输出到套件中:expect(‘’).toBe(TweetUtils);
Jasmine报道了这个:
- Expected: '' toBe: {
default: {
getListOfTweetIds: Function
},
getListOfTweetIds: Function
}
Run Code Online (Sandbox Code Playgroud)
因此看起来导入语句正在做某事,但显然不是诚实地导入我的方法.当我使用命名函数语法导入时,我得到相同的结果:import {getListOfTweetIds} from ‘../TweetUtils’;
但是如果我使用默认语法:import …
# index.js
console.log(process.argv) // expect this to print [.., .., '1']
# terminal
$ echo 1 | node index.js // just prints [.., ..]
Run Code Online (Sandbox Code Playgroud)
有什么诀窍?如何通过 unix 命令(如echo、ls、等)从命令行将参数动态传递给节点脚本ps aux?
注:我看到,我可以读取UNIX命令的输出中使用我的剧本stdin,但我想是真正的参数传递到命令行脚本。
我只希望 Webpack 查看名为“.stories”的目录中的文件,但它们可以位于src/目录结构中的任意位置。
例如,我的 na\xc3\xafve 尝试如下所示:
\n\n/*\nsrc/\n some.story.js <-- don\'t get this\n |_components/\n |_Button/\n |_ .stories/ <--\n |_ index.js <-- ignore this\n |_ utils.js <-- ignore this\n |_ main.story.js <-- get this\n |_Forms/\n |_ TextField\n |_ .stories/ <-- same kind of thing\n */\n\n\n\n\n// require.context API\n// require.context(directory to search, shouldSearchSubDirs?, fileNameRegex)\n\nrequire.context(\'src/**/.stories\', true, /\\.story\\.js$/)\nRun Code Online (Sandbox Code Playgroud)\n\n到目前为止,API 似乎希望我对文件名进行所有模式匹配。但仅文件名不足以排除.story.js其他目录中的文件。我想允许目录.story.js之外的文件.stories/,并让 Webpack 忽略它们。
这可能吗?我缺少什么?
\n\n阅读官方文档时,含义是第一个参数指定一个特定目录:
\n\n\n\n\n它允许您传入要搜索的目录、指示是否也应该搜索子目录的标志以及用于匹配文件的正则表达式。
\n
对此的解读与我的目标相反,但没有任何内容明确表明这是不可能的。Webpack 是一个复杂的工具,很容易误解它的功能。 …
所以我对我的自定义npm脚本和它们运行的bash脚本之间的关系感到困惑.
编辑:我不认为这是一个孤立的bash问题.我可以通过写入echo $2 $1.sh文件并直接从终端运行它来产生下面描述的预期行为
例如
"scripts": {"report":"echo $2 $1"}
Run Code Online (Sandbox Code Playgroud)
如果我从终端运行:npm run report "first" "second"
因为在我的NPM剧本,我打电话之前,我期待它输出这样的:,但由于某种原因它总是输出第一:(编辑)$2$1second first$1first second
我通过将参数缓存为变量尝试了一种解决方法,然后打印出来:
"scripts": {"report": "(FIRST=$1 && SECOND=$2) && echo $SECOND $FIRST"}
Run Code Online (Sandbox Code Playgroud)
但是输出相同:npm run report "first" "second"=>first second
是什么赋予了?
如何使用 graphql-js 在架构中定义片段?
import graphql from 'graphql'
/* how do I do this?
fragment authorInfo on Author {
name
}
*/
Run Code Online (Sandbox Code Playgroud)
例如,要定义作者类型,我会:
import graphql from 'graphql'
export default new graphql.GraphQLObjectType({
description: `An author`,
name: {
description: `The author's legal name.`,
type: GraphQLString
}
}),
name: `Author`
})
Run Code Online (Sandbox Code Playgroud)
所以这里的类型定义是由 生成的GraphQLObjecType。什么函数会生成片段?
javascript ×5
node.js ×3
bash ×2
jestjs ×2
babeljs ×1
ecmascript-6 ×1
flowtype ×1
graphql ×1
graphql-js ×1
neo4j ×1
npm ×1
shell ×1
webpack ×1