我想在我的程序中使用sessionStorage
,但我需要将变量存储为整数。可以使用parseInt()
吗?像:
sessionStorage.setItem("j",0);
var j = parseInt(sessionStorage.getItem("j"));
答案 0 :(得分:1)
您确定可以,但您编写的代码需要将describe('login', () => {
context('When it fails', () => {
before('Stub the api', () => {
sinon.stub(api, 'login', () => {
// IT NEVER COMES HERE !
return Promise.reject({ error: 'user not found' });
});
});
it('should return a LOGIN_FAIL action', () => {
const action = {
payload: {
name: 'toto',
password: '123456'
}
};
const generator = login(action);
// THE CALL YIELD
generator.next();
const expectedResult = put({ type: 'LOGIN_FAIL', payload: { error: 'user not found' } });
expect(generator.next().value).to.be.eql(expectedResult); // FAIL BECAUSE I GET A LOGIN_SUCCESS INSTEAD OF A FAIL ONE
});
});
});
更改为localStorage
。像这样:
sessionStorage
希望有所帮助!