jejacks0n / teaspoon

Teaspoon: Javascript test runner for Rails. Use Selenium, BrowserStack, or PhantomJS.
1.43k stars 243 forks source link

Fixture.load XMLhttpRequest deprecated? #521

Open msmith1114 opened 7 years ago

msmith1114 commented 7 years ago

I just noticed when doing some browser logging that im getting this:

XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

looking in deeper it's referring to Fixture.load

xhrRequest  @   teaspoon-jasmine2.self.js?body=1:405
load    @   teaspoon-jasmine2.self.js?body=1:303
Teaspoon.Fixture.Fixture.load   @   teaspoon-jasmine2.self.js?body=1:257
Teaspoon.Jasmine2.Fixture.Fixture.load  @   teaspoon-jasmine2.self.js?body=1:1318

Am I doing something wrong by using Fixture.load('name of file here') to use in my tests, is there another way that I should be using?

Thanks

ljluestc commented 2 days ago
Teaspoon.Fixture.prototype.load = function(url) {
  return fetch(url)
    .then(response => {
      if (!response.ok) {
        throw new Error('Network response was not ok');
      }
      return response.text();
    })
    .then(html => {
      // Here you might want to append the HTML to the DOM or something similar
      console.log(html);
      return html;
    })
    .catch(error => {
      console.error('There has been a problem with your fetch operation:', error);
    });
};

// Usage
Teaspoon.Fixture.load('path/to/fixture.html').then(content => {
  // Use the fixture content as needed
  console.log(content);
});