Mirage blocking Ember.js ajax POST request from going through

Currently, I am in the process of writing tests for a component within my Ember application. This particular component is responsible for executing an ajax POST request to communicate with my servers API and retrieve a file location string as a response.

To simulate this interaction, I have included a route in the mirage/config.js file that should handle the ajax request.

this.post('/foobar', () => {
  return "test";
});

Upon running my tests, I noticed in both the network tab and console that the ajax request is attempting to connect to localhost but encounters a Connection Refused error:

POST http://localhost:8000/foobar net::ERR_CONNECTION_REFUSED
.

Even after placing a debugger in the mirage/config.js file, it appears that the route configuration is being overlooked during testing, despite having all the necessary URL and namespace settings configured.

When launching my application on localhost and accessing the endpoint, Mirage correctly handles the request. However, this behavior does not extend to testing scenarios.

The snippet below demonstrates the code responsible for initiating the ajax request:

ajax.request(
    uri.toString(),
    {
      headers: ajax.get('headers'),
      method: 'POST',
      data: data
    });

This ajax call is triggered by a button click event, which I emulate through my integration test suite.

In light of these observations, I seek guidance on how to conduct further testing and address the discrepancy preventing the requests from flowing through Mirage effectively.

Answer №1

After some investigation, I discovered that the issue stemmed from how I initialized mirage in my integration test.

By following the instructions provided in the link above, I was able to properly initialize mirage and successfully run my tests.

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

Utilizing util.format to enclose every string within an array with double quotation marks

Currently .. var utility = require("utility"); var carsInput = 'toyota,chevrolet'; var cars = carsInput.split(','); var queryString = utility.format('Cars: [%s]', cars); console.log(queryString); // Cars: [toyota,chevrolet] ...

Fill an HTML table with comma-separated values (CSV) information

After conducting some research on the internet, I attempted to modify a jQuery script in order to populate an HTML table with data from a CSV file. However, I encountered an issue as the table remained empty. Below, you can find the code that I used. Any a ...

Using jest.fn() to simulate fetch calls in React

Can anyone explain why I have to include fetch mock logic within my test in order for it to function properly? Let's take a look at a simple example: Component that uses fetch inside useEffect and updates state after receiving a response: // Test.js ...

The Lifecycle of an ASPX Page when Invoking [WebMethod]s

Currently, I am utilizing jQuery ajax to call multiple methods that have been decorated with [WebMethod]. These methods rely on a database connection established in an external library, which remains consistent across all functions. In the initial impleme ...

Arrange the columns in Angular Material Table in various directions

Is there a way to sort all columns in an Angular material table by descending order, while keeping the active column sorted in ascending order? I have been trying to achieve this using the code below: @ViewChild(MatSort) sort: MatSort; <table matSort ...

A straightforward redirection in Express involving a static file

Just starting out with Node and Express and encountering a bit of trouble. I have a static html page where users enter their username via ajax to my server, and then I want to redirect them to another html file. const express = require("express"); const b ...

Adjusting webpage zoom based on different screen sizes

Hey there, I ran into an issue with my web page design. It looks great on my desktop monitors, but when I checked it on my laptop, things went haywire. Strangely, adjusting the zoom to 67% seemed to fix the problem. Both screens have a resolution of 1920 ...

I created an image that can be clicked on, but unfortunately it only functions properly on the

I am currently working on creating an image that can be clicked to cycle through different images all within the same frame. While I have managed to get it to work, I am facing a limitation where it only responds to one click. count = 1; function myF ...

What is the best way to target an HTML attribute using jQuery?

I have customized a Textbox by adding a special attribute: <asp.TextBox MyCustomAttribute="SomeValue"><asp.TextBox> Now, I want to retrieve this value from within an AJAX success function. Please note that I have excluded irrelevant attribut ...

Setting up Authorization for FETCH requests in NEXT.js using .env.local

`export default function reservations() { let [reservationStock, setReservationStock] = useState([]); useEffect(() => { fetch(url, { headers: new Headers({ Authorization: "MyBasic Credentials", " ...

Use AJAX, PHP, and MySQL to implement a date filtering feature

Having trouble implementing a date filter: The structure of my database is as follows: start_date | end_date 2000 | 2005 This is how my PHP select query looks: if (empty($processo) && empty($ano)){ $pegaSonda = $pdo->prepare("SELECT ...

Resizable table example: Columns cannot be resized in fixed-data-table

I've implemented a feature similar to the Facebook example found here: https://facebook.github.io/fixed-data-table/example-resize.html You can find my source code (using the "old" style with React.createClass) here: https://github.com/facebook/fixed- ...

Using Javascript to Highlight a Single Row in a Table

Greetings esteemed members of the skilled community at StackOverflow, I must humbly ask for your expertise in solving a dilemma that I am currently facing. The situation is as follows: I have a table generated from an SQL query, and it is crucial for the ...

Javascript is coming back with a message of "Access-Control-Allow-Origin" not being allowed

I've been encountering some unusual challenges with my React application related to the Access-Control-Allow-Origin issue. Initially, I had similar issues with the login and registration system which I thought were resolved, but now I'm facing di ...

Using v-bind and AJAX in Vue.js

Transitioning from jQuery to Vue 2.0 has been a breeze for the most part, but I am facing challenges when it comes to handling AJAX calls and working with responses in Vue. One specific issue is related to a "Modal trigger" that opens a modal window upon ...

How to format time in Node.js using PostgreSQL

I have set up two tables in my Postgres database, one called users and the other called card_info. I have implemented an endpoint for new user registration, and I have included a field named dateCreated in the code snippet below. Register.js const handle ...

Experiencing an Issue with NGINX Loading Vue 3 Vite SPA as a Blank White Page

I currently have the following NGINX configuration set up: events { worker_connections 1024; } http { server { listen 80; server_name localhost; location / { root C:/test; index index.html; ...

The issue of fonts module resolution in React-Native remains unsolved

I am embarking on a basic build project using 'create-react-native-app' and yarn as the package manager. My main goal is to incorporate 'native-base' for enhancing the user interface. So far, the only addition to my app.js file is a B ...

Tips for preserving login status even after the browser is shut down with the help of JavaScript

I need help with maintaining a user session in my chat application even when the browser is closed. After users log in for the first time, I want their credentials to be remembered by the browser (I'm currently using local storage). How can I ensure ...

What steps should I take when dealing with two dynamic variables in a mediator script within the WSO2 ESB?

I'm facing an issue with my if condition - it doesn't work properly when the value is static. However, when I make `annee2` and `annee1` static (for example =2019), it works fine. Here's the code snippet: <script language="js"&g ...