0

I am new to Cypress and using it to e2e my angular 14 app. I have an Angular component I am testing. I am trying see how the components public variable value changes given different interaction with the DOM.

The component itself is very complicated But I have a stripped down example

export class AgePricingComponent{
   pricing = new Pricing();

   onClick() {
      pricing.amount = 5;
   }
}

In my test I want to test that pricing.amount = 5; so I use the following test:

  it('should set all of the age pricing', () => {
    cy.get('#age-amount-0').clear().type(-5);
    cy.get('#submit-btn').click(); 
    cy.window().then((win)=>{
      let pricing = win.pricing.amount;
      cy.log(pricing); expect(pricing.amount).equals(-5);

    })
  });

The error I get is

TypeError: win.pricing is undefined at ./cypress/e2e/admin/create-new-tournament.cy.js/</ (webpack:///./cypress/e2e/admin/create-new-tournament.cy.js:40:20) at getRet (http://localhost:4200/__cypress/runner/cypress_runner.js:139235:20) From previous event: at thenFn (http://localhost:4200/__cypress/runner/cypress_runner.js:139249:60) at then (http://localhost:4200/__cypress/runner/cypress_runner.js:139671:21) at wrapped (http://localhost:4200/__cypress/runner/cypress_runner.js:157819:19) at ../driver/src/cypress/command_queue.ts/runCommand (http://localhost:4200/cypress/runner/cypress_runner.js:156547:15) From previous event: at runCommand (http://localhost:4200/cypress/runner/cypress_runner.js:156524:8) at next (http://localhost:4200/cypress/runner/cypress_runner.js:156684:19) From previous event: at next (http://localhost:4200/cypress/runner/cypress_runner.js:156684:39) at ../driver/src/cypress/command_queue.ts/run/next (http://localhost:4200/cypress/runner/cypress_runner.js:156706:16) at createLog (http://localhost:4200/cypress/runner/cypress_runner.js:135510:64) at onReady (http://localhost:4200/cypress/runner/cypress_runner.js:135557:18) at runAllChecks (http://localhost:4200/cypress/runner/cypress_runner.js:133577:14) at retryActionability (http://localhost:4200/cypress/runner/cypress_runner.js:133586:16) at whenStable (http://localhost:4200/cypress/runner/cypress_runner.js:153059:62) at ../driver/src/cy/retries.ts/create/retry (http://localhost:4200/cypress/runner/cypress_runner.js:152468:14) at retry (http://localhost:4200/cypress/runner/cypress_runner.js:152448:60) at retryActionability (http://localhost:4200/cypress/runner/cypress_runner.js:133589:19) at ../driver/src/cy/actionability.ts/verify (http://localhost:4200/cypress/runner/cypress_runner.js:133593:12) at verify (http://localhost:4200/cypress/runner/cypress_runner.js:133498:58) at perform (http://localhost:4200/cypress/runner/cypress_runner.js:135541:77) From previous event: at next (http://localhost:4200/cypress/runner/cypress_runner.js:156684:39) From previous event: at ../driver/src/util/queue.ts/run/promise< (http://localhost:4200/cypress/runner/cypress_runner.js:172145:77) From previous event: at run (http://localhost:4200/cypress/runner/cypress_runner.js:172140:21) at run (http://localhost:4200/cypress/runner/cypress_runner.js:156756:15) at runQueue (http://localhost:4200/cypress/runner/cypress_runner.js:157795:14) at ../driver/src/cypress/cy.ts/addCommand/cy[name] (http://localhost:4200/cypress/runner/cypress_runner.js:157894:12) at ./cypress/e2e/admin/create-new-tournament.cy.js/ (webpack:///./cypress/e2e/admin/create-new-tournament.cy.js:37:7) at ../driver/src/cypress/cy.ts/setRunnable/runnable.fn (http://localhost:4200/cypress/runner/cypress_runner.js:158077:43) at callFn (http://localhost:4200/cypress/runner/cypress_runner.js:107989:21) at ../driver/node_modules/mocha/lib/runnable.js/</Runnable.prototype.run (http://localhost:4200/cypress/runner/cypress_runner.js:107976:13) at ../driver/src/cypress/runner.ts/create/onRunnableRun (http://localhost:4200/cypress/runner/cypress_runner.js:165418:30) at fn (http://localhost:4200/cypress/runner/cypress_runner.js:154293:16) at onack (http://localhost:4200//assets/index.54591923.js:34097:11) at onpacket (http://localhost:4200//assets/index.54591923.js:34041:14) at Emitter2.prototype.emit (http://localhost:4200//assets/index.54591923.js:32213:23) at emitReserved (http://localhost:4200//assets/index.54591923.js:33890:11) at ondecoded (http://localhost:4200//assets/index.54591923.js:34367:10) at Emitter2.prototype.emit (http://localhost:4200//assets/index.54591923.js:32213:23) at add (http://localhost:4200//assets/index.54591923.js:33739:17) at ondata (http://localhost:4200//assets/index.54591923.js:34364:18) at Emitter2.prototype.emit (http://localhost:4200//assets/index.54591923.js:32213:23) at onPacket (http://localhost:4200//assets/index.54591923.js:33242:16) at setTransport (http://localhost:4200//assets/index.54591923.js:33111:13) at Emitter2.prototype.emit (http://localhost:4200//assets/index.54591923.js:32213:23) at onPacket (http://localhost:4200//assets/index.54591923.js:32275:10) at onData (http://localhost:4200//assets/index.54591923.js:32272:10) at addEventListeners/this.ws.onmessage (http://localhost:4200//assets/index.54591923.js:32864:38) at EventHandlerNonNull*addEventListeners (http://localhost:4200//assets/index.54591923.js:32864:5) at doOpen (http://localhost:4200//assets/index.54591923.js:32854:10) at open (http://localhost:4200//assets/index.54591923.js:32247:12) at open (http://localhost:4200//assets/index.54591923.js:33097:16) at Socket$2 (http://localhost:4200//assets/index.54591923.js:33051:10) at lib$3.exports (http://localhost:4200//assets/index.54591923.js:33404:32) at open (http://localhost:4200//assets/index.54591923.js:34306:19) at Manager (http://localhost:4200//assets/index.54591923.js:34252:12) at lookup (http://localhost:4200//assets/index.54591923.js:34509:23) at createWebsocket$1 (http://localhost:4200//assets/index.54591923.js:34533:10) at createWebsocket (http://localhost:4200//assets/index.54591923.js:106567:32) at (http://localhost:4200//assets/index.54591923.js:106761:27) From previous event: at onRunnableRun (http://localhost:4200/__cypress/runner/cypress_runner.js:165403:46) at action (http://localhost:4200/__cypress/runner/cypress_runner.js:154101:28) at ../driver/src/cypress/mocha.ts/patchRunnableRun/Runnable.prototype.run (http://localhost:4200/__cypress/runner/cypress_runner.js:163059:13) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.runTest (http://localhost:4200/__cypress/runner/cypress_runner.js:108648:10) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.runTests/next (http://localhost:4200/__cypress/runner/cypress_runner.js:108774:12) at next (http://localhost:4200/__cypress/runner/cypress_runner.js:108557:14) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.hooks/next (http://localhost:4200/__cypress/runner/cypress_runner.js:108567:11) at next (http://localhost:4200/__cypress/runner/cypress_runner.js:108469:14) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.hook (http://localhost:4200/__cypress/runner/cypress_runner.js:108535:9) at timeslice (http://localhost:4200/__cypress/runner/cypress_runner.js:102461:27) at setTimeout handler*../driver/node_modules/mocha/browser-entry.js/</Mocha.Runner.immediately (http://localhost:4200/__cypress/runner/cypress_runner.js:102477:24) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.hook (http://localhost:4200/__cypress/runner/cypress_runner.js:108534:10) at ../driver/src/cypress/utils.ts/monkeypatchBefore (http://localhost:4200/__cypress/runner/cypress_runner.js:167465:23) at next (http://localhost:4200/__cypress/runner/cypress_runner.js:108560:10) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.hooks (http://localhost:4200/__cypress/runner/cypress_runner.js:108571:7) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.hookUp (http://localhost:4200/__cypress/runner/cypress_runner.js:108583:8) at ../driver/node_modules/mocha/lib/runner.js/</Runner.prototype.runTests/next/ (http://localhost:4200/__cypress/runner/cypress_runner.js:108809:14) at next (http://localhost:4200/__cypress/runner/cypress_runner.js:165309:24) at ../driver/src/cypress/runner.ts/create/onRunnableRun/onNext (http://localhost:4200/__cypress/runner/cypress_runner.js:165338:17) index.54591923.js:99867:13

How can I check that value of my public pricing property?

Ken
  • 423
  • 6
  • 13

0 Answers0