我在使用sinon和chai在javascript中编写测试时遇到了问题.我正在尝试检查是否在间谍上调用了一个函数并获得"错误:无效的Chai属性:calledOnce"
我在另一个具有相同测试依赖性的项目中做同样的事情没有任何问题......
var udpSocketStub = this.sandbox.spy(udpSocket, 'send');
expect(udpSocketStub).calledOnce; // SHOULD FAIL
"dependencies": {
"body-parser": "~1.17.1",
"bootstrap": "^4.0.0-alpha.6",
"chai": "^4.1.0",
"co-mocha": "^1.2.0",
"cookie-parser": "~1.4.3",
"debug": "~2.6.3",
"express": "~4.15.2",
"jquery": "^3.2.1",
"mocha": "^3.4.2",
"morgan": "~1.8.1",
"node-compass": "0.2.3",
"pug": "^2.0.0-rc.1",
"serve-favicon": "~2.4.2",
"sinon": "^2.3.8",
"sinon-chai": "^2.12.0"
}
Run Code Online (Sandbox Code Playgroud) 我想显示,react-bootstrap-modal但只有叠加显示和模态不显示
import Modal from 'react-bootstrap-modal';
......
<Modal
show={this.state.open}
onHide={this.closeModal}
aria-labelledby="ModalHeader"
>
<Modal.Header closeButton>
<Modal.Title id='ModalHeader'>A Title Goes here</Modal.Title>
</Modal.Header>
<Modal.Body>
<p>Some Content here</p>
</Modal.Body>
<Modal.Footer>
// If you don't have anything fancy to do you can use
// the convenient `Dismiss` component, it will
// trigger `onHide` when clicked
<Modal.Dismiss className='btn btn-default'>Cancel</Modal.Dismiss>
// Or you can create your own dismiss buttons
<button className='btn btn-primary'>
Save
</button>
</Modal.Footer>
</Modal>
.....
Run Code Online (Sandbox Code Playgroud)
截图:

我有一个包含标题,描述和图像URL属性的10个对象的数组(让我们称之为"博客").我需要在HTML标记中包装每个属性并将它们全部导出,以便它们一起加载到网页上.
使用我当前的代码,我只获得页面上当前状态加载中的一个对象.如何让所有对象处于相同状态?
class NewBlogs extends React.Component {
constructor(props) {
this.state = {
title: [],
description: [],
image: [],
loading: true
};
}
componentDidMount() {
axios.get('/new-blogs').then(data => {
const blogs = data.data;
var component = this;
for(var i in blogs) {
component.setState({
title: blogs[i].title,
description: blogs[i].description,
image: blogs[i].image,
loading: false
});
}
})
.catch(function(error) {
console.log(error);
});
}
render() {
return (
<div>
<h2>New Blogs:</h2>
<h3>{this.state.title}</h3>
<em>{this.state.description}</em>
<img src={this.state.image}></img>
</div>
);
}
}
export default NewBlogs
Run Code Online (Sandbox Code Playgroud) 代码如下:
import pygame, sys
from pygame.locals import *
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
WHITE = (255, 255, 255)
GRASSCOLOR = GREEN
BGCOLOR = WHITE
WINDOWWIDTH = 500
WINDOWHEIGHT = 300
def main():
pygame.init()
global DISPLAYSURF
DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
pygame.display.set_caption('Platformer')
player = pygame.image.load('megaman_running_sprites_by_cobalt_blue_knight-d2y1i8s.png')
playerx = 140
playery = 10
DISPLAYSURF.fill(BGCOLOR)
DISPLAYSURF.blit(player, (10, 140))
while True: # Event handling loop
ground()
mousex, mousey = pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type …Run Code Online (Sandbox Code Playgroud) 我有一堆文件和几个文件夹。我正在尝试将 zip 附加到列表中,以便我可以在代码的其他部分提取这些文件。它永远找不到拉链。
for file in os.listdir(path):
print(file)
if file.split(".")[1] == 'zip':
reg_zips.append(file)
Run Code Online (Sandbox Code Playgroud)
路径很好,否则它不会打印出任何东西。它每次都会选取相同的文件,但不会选取任何其他文件。它获取目录中大约 1/5 的文件。
完全亏本。我已经通过在代码中放入 time.sleep(3) 来确保文件可用性的一些奇怪的竞争条件不是问题。没解决。
reactjs ×2
directory ×1
file ×1
javascript ×1
listdir ×1
pygame ×1
python ×1
sinon ×1
sinon-chai ×1