Trying out a function named on Sinon.js spy

Currently, I am utilizing SinonJS to verify that my controller is calling certain methods within my view. Specifically, I am aiming to confirm that the addSeat method is invoked with the value of testSeat. Despite my efforts in the code snippet below, I am encountering an error. I am seeking a way to conduct this test without needing to incorporate my view module into the testing process. Is there a way to achieve this?

describe('Adding a seat', function() {
  view1Spy = {
        addSeat: sinon.spy(),
        render: sinon.spy()
  };
  beforeEach(function() {
    newSeat = seatingChartController.addSeat(3, 4);
    seatingChartController.registerView(view1Spy);
  });
  it('Calls addSeat on each view with the added seat', function() {
    expect(view1Spy.addSeat).to.be.calledWith(newSeat);
  });
}

UPDATE:

Here is the specific error message that I am encountering:

1) Seating Chart Controller Adding a seat Calls addSeat on each view with the added seat
     Failure/Error: 'undefined' is not a function (evaluating 'expect(view1Spy.addSeat).to.be.calledWith(newSeat)'

Answer №1

For this scenario, the ideal solution would involve implementing the following code snippet:

spyOnView1 = {updateReservation: sinon.spy()};
// ...
expect(spyOnView1.updateReservation.calledWith(updatedReservation)).to.be.true;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Best Practices for Organizing Image and JavaScript Files in Your Project

Currently, I am working on a project in Eclipse and I'm unsure about the proper location to store my image files and JavaScript files. Can anyone provide guidance on this matter? Thank you. ...

Set up two unique production servers with different environment variables in NextJs

For my Next.js project, I encountered a challenge while deploying a new version of the app to a development server that relies on environment variables from .env.development. Our typical process includes the following steps: Develop the new fe ...

Tips for avoiding background-image zoom on mobile browsers when stacking elements vertically:

Within my ReactJS application, I have implemented a feature where elements are added vertically from top to bottom when the "Post" button is clicked. https://i.sstatic.net/KwPYV.jpg These elements display correctly on both mobile and desktop browsers. Ho ...

Convert HTML element to a JSON object

Here is an example of an HTML element: <div class='myparent'> <div> <div class="pdp-product-price"> <span> 650 rupees</span> <div class="origin-block"> <sp ...

What could be the reason why I am unable to choose my radio button? What error am I

The output can be found here... I am struggling to use a radio button and cannot seem to select it. Can someone please explain what issue I am facing? Any help would be greatly appreciated. const [value, setValue] = React.useState({ yes:"", no:"" ...

To activate the speech synthesis feature with a message, you must click a button for it to work

The issue with the code snippet below is that the function "window.speechSynthesis.speak(msg)" does not produce any sound output unless the button is clicked first. Only after clicking the button, the "Hello" message works as intended. Any attempts to call ...

Sequencing asynchronous functions in Angular: Ensuring one function runs before another

When working with a save function that requires you to call another function to retrieve the revision number and make an API call, both of which are asynchronous in nature, how can you ensure one function waits for the other to execute? $scope.getRevision ...

Implement AJAX in order to circumvent fees from Google Maps and display maps exclusively upon user interaction by clicking a designated button

Starting July 16, 2018, the Google Maps API is no longer completely free. After July 16, 2018, in order to continue utilizing the Google Maps Platform APIs, you must activate billing for each of your projects. (https://developers.google.com/maps/documentat ...

Eradicating a character from an Object using Jquery/Javascript

Looking at this code snippet, it appears that the 3rd column is not calculating correctly due to a comma being present in one of the values. Is there a way to rectify this issue without directly removing the comma? I am aware that using .replace(/,/g,&apos ...

javascript to retrieve data by reducing

Here is the code snippet I am working with: var points = 4; var yModifier = []; for (var i = 0; i <= points; i++) { yModifier.push([]); }; yModifier.forEach( (a, j) => { var start = j; var end = start + points; fo ...

Steps for creating a personalized popup window

Is there a way to create a custom dialog box that includes images, input fields, and more, similar to the design on this website? Any suggestions on what tools or methods I could use to achieve this? ...

Tips for indicating request parameters in Drive.Comments.list

I have successfully retrieved the default 20 comments using the code below by specifying a single fileId parameter. However, I am interested in pulling back one hundred comments or paginating to the next set of 20 out of curiosity. In my getComments funct ...

Double Tap Required to Update AngularJS Scope

Controller: // Modal Controller app.controller("ModalCtrl", ["$scope", "$filter", function($scope, $filter) { var date = new Date(); var currentDate = $filter('date')(new Date(), 'MM/dd/yyyy'); // Form Submit Actions $scope.s ...

rediscovering values following verification

When handling incoming requests matching /user/read/:user_id, I utilize "router.get" In "router.param", a new object named "user" is defined with attributes like name and age Later on in the code within "router.get", the user object is retrieved using ...

How can I showcase the index of `<tr>` and `<td>` elements in a dynamically generated table

How can I print the index of table rows and data on click in javascript? <html> <head> <title>Table Creation</title> <script language="javascript" type="text/javascript"> function createTable() { ...

Problems with Ajax calls are preventing Internet Explorer9 and Internet Explorer10 from functioning properly

I am facing an issue with displaying item pages using Ajax. The function works perfectly in Chrome, but not in Internet Explorer. <script type="text/javascript"> function obtainInfo(str) { if (str=="") { document. ...

Understanding the reading of Java Class List in Vue Js

As a beginner in Front-end development, I am trying to figure out how I can use Vue.js to read a Java class List. Specifically, I have a Java class that includes a list of fruits and I want to be able to display this list on the UI using Vue.js: public c ...

Notification does not appear once the full content of all iframes on the page has been loaded

<!DOCTYPE html> <html lang="en"> <head> <title> </title> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="css/custom.css" /> </head> <bo ...

Causes of the error message 'TypeError: res.render is not a function'

I have set up an express application with the following code: var express = require('express'); var router = express.Router(); var passport = require('passport'); var User = require('../models/user'); var request = require(&a ...

Can Highchart dynamically adjust color choices based on the quantity of data points available?

I am trying to figure out how to import a specific color palette into my column graph. I want to use different color palettes based on the number of data points in my graph - for 3 or fewer points, I want to use the top row colors, for 4 points I want to u ...