badeball / karma-jsdom-launcher

A Karma plugin. Launcher for jsdom.
MIT License
37 stars 16 forks source link

set userAgent invalid #26

Closed leeziiAtCn closed 5 years ago

leeziiAtCn commented 5 years ago

browsers: ['jsdom'], jsdomLauncher: { jsdom: { userAgent: 'asdasdasd' } }, i set userAgent as this, but i get jsdom default ua in test case , can u help me ?

badeball commented 5 years ago

Hi, @leeziiAtCn

The way to change user agent with jsdom changed with the new API / deprecation of the old, in version 12. See below for how you would now control the user agent (Disclaimer: I typed this straight into Github without testing it). See jsdom's own documentation for more information about configurating this.

const jsdom = require("jsdom");

module.exports = function(config) {
  config.set({
    browsers: ['jsdom'],

    jsdomLauncher: {
      jsdom: {
        resources: new jsdom.ResourceLoader({
          userAgent: "foobar",
        })
      }
    }
  });
};

I'll update the readme to reflect this.

leeziiAtCn commented 5 years ago

@badeball hi bro , thanks for your help !