store.js:15 Uncaught SyntaxError: "undefined" is not valid JSON at JSON.parse (<anonymous>) - e-commerce

Why I am getting this error?
const cartItemsFromStorage = localStorage.getItem('cartItems') ? JSON.parse(localStorage.getItem('cartItems')) : [];

Related

Uncaught TypeError: Cannot read properties of undefined (reading 'toggle')

burger.addEventListener('click', ()=> {
rightNav.classlist.toggle('v-class-resp');
navbar.classlist.toggle('h-nav-resp');
navList.classlist.toggle('v-class-resp');
})
This 'navbar' is showing error.
You should use classList, not classlist

Angular cli karma can't use json file

Am using Jasmine karma in angular-cli project.
When am trying to use a json file inside it throws an error.
import { TestBed } from '#angular/core/testing';
describe('xxxService', () => {
let service: xxxService
let attributeData: any = require('../../mock-data/testCase_mockData/attributedata.json');
beforeEach(()=>{
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [xxxService],
});
service = TestBed.get(ColorCodeEngineService);
// attributeData = Object.assign({}, require('../../mock-data/testCase_mockData/attributedata.json'));
});
});
It throws error ,
ERROR in ./src/app/mock-data/testCase_mockData/attributedata.json
Module parse failed: Unexpected end of JSON input while parsing near
'' You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected end of JSON input while parsing near ''
Is there any solutions to fix this ?

reverse array issue in VueJs

i get conversations message via facebook graph api and i need to reverse data.
in computed reverseChat function i try return this.chat.data works but not reverse() when i try JSON.parse(this.chat).data.reverse() or this.chat.data.reverse() error showing.
console show error
[Vue warn]: Error when rendering anonymous component at C:\Users\PEM\Desktop\src\components\Chat.vue:
SyntaxError: Unexpected end of JSON input
at json.parse (<anonymous>)
at Proxy.render (eval at <anonymous> (app.js:2430), <anonymous>:123:85)
at VueComponent.Vue._render (ever at <anonymous> (app.js:606), <anonymous>:2464:21)
...
sample code in jsfiddle
https://jsfiddle.net/pqrf2vu4/
JSON.parse(this.chat).data.reverse()
works. See Jsfiddle

Angular2 RC4 testing: Uncaught (in promise): TypeError: testing_1.expect(...).toBeAnInstanceOf is not a function

Here is my test in Angular2:
it('should initialize without DI service',
async(inject([TestComponentBuilder], (tcb: TestComponentBuilder) => {
var template = '<component></component>';
return tcb.overrideTemplate(TestComponent, template)
.createAsync(TestComponent)
.then((fixture ) => {
expect(fixture.debugElement.children[0].componentInstance).toBeAnInstanceOf(ComponentType);
expect(fixture.debugElement.children[0].componentInstance.state).toBeNull();
});
})));
It throws the following error:
Uncaught (in promise): TypeError:
testing_1.expect(...).toBeAnInstanceOf is not a function
It works fine in Angular2 RC2 till I updated to RC4.
Since this has been unanswered for a long time, this other post might be helpful for the future:
Uncaught TypeError: ctorParameters.map is not a function

Issue integrating Jest into React application

I recently created a react application and would like to test it. I am trying to use Jest as Facebook recommends but have run into an issue. The specific error is as follows:
FAIL __tests__/popup-test.js
● Runtime Error
SyntaxError: Unexpected token [
at Function (native)
at Array.forEach (native)
at Array.forEach (native)
npm ERR! Test failed. See above for more details.
The code for popup-test.js
'use strict';
jest.unmock('../dist/test/popup.js');
const React = require('react');
const ReactDOM = require('react-dom');
const TestUtils = require('react-addons-test-utils');
let Popup = require('../dist/test/popup.js');
describe('Popup', () => {
it('works', () => {
var popupTest = TestUtils.renderIntoDocument(
<Popup />
);
var popupNode = ReactDOM.findDOMNode(popupTest);
expect(1).toEqual(1);
});
});
As you can see, the error does not provide me with any information. I know the problem is with requiring my popup file and I can post the contents of the code here. I was hoping though that someone had encountered this problem before and could guide me in the right direction to solving it.
Best,
Aneury Casado