我要
Expected value to equal: [{"id": 1, "text": "Run the tests"}, {"id": 0, "text": "Use Redux"}] Received: [{"id": 0, "text": "Use Redux"}, {"id": 1, "text": "Run the tests"}]
我不太了解如何使减速器通过测试。我引用了各种github项目,以对测试有更好的了解。我不确定该如何做才能通过测试。这就是我所拥有的。
我使用玩笑进行测试。
actions / actions.js
let nextTodoId = 0;
export const addPost = text => ({
type: 'ADD_POST',
id: nextTodoId++,
text
})
reducers / myPosts
const initialState = [
{
text: 'Use Redux',
id: 0
}
]
const myPosts = (state = initialState, action) => {
switch(action.type){
case 'ADD_POST':
const post = {
id:state.reduce((maxId, post) => Math.max(post.id, maxId), -1) + 1,
text:action.text,
}
return [...state, post];
default:
return state
}
}
export default myPosts
测试 /reducers.js
import { addPost } from '../actions/actions';
import myPosts from '../reducers/myPosts';
import uuid from 'uuid';
describe('myPosts myPosts', () => {
it('should return the initial state', () => {
expect(myPosts(undefined, {})).toEqual([
{
text: 'Use Redux',
id: 0
}
])
})
it('should handle ADD_POST', () => {
expect(
myPosts([], {
type: 'ADD_POST',
text: 'Run the tests'
})
).toEqual([
{
text: 'Run the tests',
id: 0
}
])
expect(
myPosts(
[
{
text: 'Use Redux',
id: 0
}
],
{
type: 'ADD_POST',
text: 'Run the tests',
id:0
}
)
).toEqual([
{
text: 'Run the tests',
id: 1
},
{
text: 'Use Redux',
id: 0
}
])
})
})
答案 0 :(得分:1)
问题是您在添加新帖子之前先扩展了以前的状态...
将减速器更改为此:
/anaconda3/lib/python3.6/site-packages/keras/layers/core.py in call(self, inputs, mask)
691 if has_arg(self.function, 'mask'):
692 arguments['mask'] = mask
--> 693 return self.function(inputs, **arguments)
694
695 def compute_mask(self, inputs, mask=None):
/anaconda3/lib/python3.6/site-packages/keras/layers/core.py in <lambda>(x)
334 print('gates_shape', gates_shape)
335 for ii, kk in enumerate(prms.label_cols):
--> 336 slicer = Lambda(lambda x: x[:,:,:,ii:ii+1],
337 output_shape=gates_shape[:-2]+(1,),
338 name='slice_'+kk)
NameError: name 'ii' is not defined
您编写的方式...新帖子放置在状态数组的末尾。如果您希望新帖子首先出现,将解决此问题。