last day (19 days later) » 

16:14
Hello
@Prince hi prince
can you please post the new error
sure, one moment
OTAL: 1 FAILED, 9 SUCCESS
TOTAL: 1 FAILED, 9 SUCCESS

ERROR in src/app/orderDetails/components/order-details/order-details.page.spec.ts:23:5 - error TS2741: Property 'getData' is missing in type 'Spy<() => any>' but required in type '{ getData: () => void; }'.

23 mockDataService = spyOn(datasvc, "getData").and.returnValue({ order: { id: "12", description: "desc" } });
~~~~~~~~~~~~~~~

src/app/orderDetails/components/order-details/order-details.page.spec.ts:15:27
15 let mockDataService = {getData: () => {} };
i have added the modified spec file in the question as edit
give me 2 min
let me redesign code with data types
sure
16:24
ohhhh
1 more thing, can you please check again
by overriding below line
mockDataService = spyOn(mockDataService,"getData").and.returnValue({order : {id : "12",description:"desc"}});
ok, trying
i forgot to override datasvc with mockDataService
that error is gone, now below one came..
07 03 2020 21:57:35.786:INFO [launcher]: Starting browser Chrome

ERROR in src/app/orderDetails/components/order-details/order-details.page.spec.ts:23:73 - error TS2345: Argument of type '{ order: { id: string; description: string; }; }' is not assignable to parameter of type 'void'.

23 mockDataService = spyOn(mockDataService, "getData").and.returnValue({ order: { id: "12", description: "desc" } });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

07 03 2020 21:57:37.706:INFO [Chrome 80.0.3987 (Mac OS X 10.14.6)]: Connected on socket P4D6IOAkTEzw3z
buddy its data type issue
see the data type specified by you in component class
and you are returning different data type from test class
oh.. one moment
16:30
You have one property called data in component file ?
what can be data type
I have it like this..
export class OrderDetailsPage implements OnInit {

orderData: Order;
users: Map<any, any>;
location$: Subscription;
data : any;

constructor(
private dataService: DataService,
yes but what do you want to store in data?? it should not be any
and why are you returning { order: { id: "12", description: "desc" } } in test ccases
can it be like this..
data : {order : any};
why are you returning { order: { id: "12", description: "desc" } } in test ccases - No reason , just for UI elements for purpose.. if that is the issue, I can remove it
Right for UI elements
it means data is an object
with some properties
it mean is has a shape
what shape do you want
correct
like this structure - { id: "12", description: "desc" }
16:36
ok
in component use data !: {id: string, description: string}
this is the UI..
<ion-row class="only-border">
<ion-col>
ID
</ion-col>
<ion-col>
{{orderData.id}}
</ion-col>
</ion-row>
<ion-row class="only-border">
<ion-col>
description
</ion-col>
<ion-col>
{{orderData.description}}
</ion-col>
</ion-row>
ok, trying
wait buddy
In template, you are not even using data object
yes, data is just a dynamic place holder..
orderData is retrieved from data.
ohhh got it
orderData: Order;
In above line Order is Interface
right ?
correct
16:41
can you post it here ?
Order interface
data !{ order: { id: "12", description: "desc" } }
export interface Order {
sourceSystem?: any,
projectId?: any,
orderId: any,
orderType: any,
orderDescription: any,
priority?: any,
status?: any,
createdUser?: any,
creationTime?: any,
assignedUsers?: any,
location: any,
dueDate?: any,
complianceDate?: any,
comments?: any

}
Use this -> data !: {order: Order}
and run code
it should resolve
ok
should I have to change anything in mockDataService..
mockDataService = spyOn(mockDataService, "getData").and.returnValue({ order: { orderId: "12", orderDescription: "desc" } });
It is erroring out like this..

ERROR in src/app/orderDetails/components/order-details/order-details.page.spec.ts:23:73 - error TS2345: Argument of type '{ order: { orderId: string; orderDescription: string; }; }' is not assignable to parameter of type 'void'.

23 mockDataService = spyOn(mockDataService, "getData").and.returnValue({ order: { orderId: "12", orderDescription: "desc" } });
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
i just changed the id to orderId and description to orderDescription according to Order interface
same error with old values as well.
16:47
ok , no no use Interface values only
let mockDataService = { getData: () => { } } as DataService;
replace this line as well
lot of datatypes are not mentioned
and we should never use any
yes.. realized the issue of any today..
trying the above one
16:49
if it doesnot resolve, please post your component and test code here only. I will check again
ok, should I comment the line
mockDataService = spyOn
please post code here
seems like some formatting issue as well
ok .. one moment
COmponent file:

import { Component, OnInit } from '@angular/core';
import { DataService } from './../../../services/data.service';
import { WorkFlowService } from './../../../services/work-flow.service';
import { NotificationService } from './../../../services/notification.service';
import { Subscription } from 'rxjs';
import { environment } from './../../../../environments/environment';
import { Order } from 'src/app/models/order';

@Component({
selector: 'app-order-details',
templateUrl: './order-details.page.html',
Test file:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';

import { OrderDetailsPage } from './order-details.page';
import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing";
import { RouterModule } from '@angular/router';
import { DataService } from 'src/app/services/data.service';



describe('OrderDetailsPage', () => {
let component: OrderDetailsPage;
let fixture: ComponentFixture<OrderDetailsPage>;
const mockDataService = jasmine.createSpyObj('DataService', ['getData']).and.returnValue({order: { orderId: "12", orderDescription: "desc" }})
use above line
and delete below 2 lines
17:03
let mockDataService = { getData: () => { } } as DataService;
mockDataService = spyOn(mockDataService, "getData").and.returnValue({ orderId: "12", orderDescription: "desc" });
ok
Chrome 80.0.3987 (Mac OS X 10.14.6) OrderDetailsPage should create FAILED
Failed: Cannot read property 'returnValue' of undefined
at <Jasmine>
modified test file:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';

import { OrderDetailsPage } from './order-details.page';
import { HttpClientTestingModule, HttpTestingController } from "@angular/common/http/testing";
import { RouterModule } from '@angular/router';
import { DataService } from 'src/app/services/data.service';



describe('OrderDetailsPage', () => {
let component: OrderDetailsPage;
let fixture: ComponentFixture<OrderDetailsPage>;
never use this line
var datasvc = new DataService();
oops...removing
same error after removing
WARN: 'Ionic Angular was already initialized. Make sure IonicModule.forRoot() is just called once.'
Chrome 80.0.3987 (Mac OS X 10.14.6): Executed 6 of 10 SUCCESS (0 secs / 0.374 secs)
Chrome 80.0.3987 (Mac OS X 10.14.6) OrderDetailsPage should create FAILED
Failed: Cannot read property 'returnValue' of undefined
at <Jasmine>
at UserContext.<anonymous> (http://localhost:9876/_karma_webpack_/src/app/orderDetails/components/order-details/order-details.page.spec.ts:27:81)
at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:359:1)
its some different error
17:21
const mockDataService = jasmine.createSpyObj<DataService>('DataService', ['getData']).and.returnValue({order: { orderId: "12", orderDescription: "desc" }})
can you try it like this
ok
Property 'and' does not exist on type 'SpyObj<DataService>'
no idea buddy
would suggest you last thing
write this statement inside describe block

const mockDataService: jasmine.SpyObj<Geolocation>;
not const use let
let mockDataService: jasmine.SpyObj<Geolocation>;
and then replace
const mockDataService = jasmine.createSpyObj<DataService>('DataService', ['getData']).and.returnValue({order: { orderId: "12", orderDescription: "desc" }})
with
const mockDataService = jasmine.createSpyObj<DataService>('DataService', ['getData']).and.returnValue({order: { orderId: "12", orderDescription: "desc" }})
const mockDataService = jasmine.createSpyObj<DataService>('DataService', ['getData']).and.returnValue({order: { orderId: "12", orderDescription: "desc" }})
with
mockDataService = jasmine.createSpyObj<DataService>('DataService', ['getData']).and.returnValue({order: { orderId: "12", orderDescription: "desc" }})
ok.. I will try.
I am fortunate you spent time and gave your best on this. Thanks a ton.
However..I keep trying alternatives and keep you posted if it works
sure
i would suggest you to create a stackblitz instance for angular questions
it is easy in stackoverflow to answer quickly
if error is reproducible, so that i can fix at my end
17:38
yes.. I did not thought this is tricky.. I will reproduce and share. You may check if your time permits
sure

  last day (19 days later) »