Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #20957
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2013-08-15 04:28 -0700 |
| References | <1e4f5146-6d0d-4161-a2ec-7c302acfbe94@googlegroups.com> |
| Message-ID | <7b4ad082-ced6-4602-bf65-6967cd67fe7c@googlegroups.com> (permalink) |
| Subject | Re: require.js in a phantomjs test fails for code that works fine in production |
| From | Carlos Pedro <carlospedr@gmail.com> |
You must include the file where Data is defined in your tests like you do in the
documents you are loading to your page, otherwise Data won't be defined and
you'll get that reference error.
Hope I helped.
On Wednesday, August 14, 2013 1:29:33 AM UTC+2, David Karr wrote:
> I have a small webapp whose javascript code I don't normally maintain. I work on the back-end of the service, but that's irrelevant to the question.
>
>
>
> I'm trying to implement javascript unit tests. Someone helped me put together a configuration using maven, jstestrunner, phantomjs, and qunit, along with one trivial unit test.
>
>
>
> This configuration works, except I had to add one line of code to the CUT (code under test) that the code running in production doesn't need. It still works in production with the added line, but I need to understand why the test requires the line.
>
>
>
> In short, one of the several .js files begins like this:
>
>
>
> -------------------
>
> Data.Daily = new Function();
>
>
>
> Data.Daily.prototype = {
>
> ...
>
> -----------------
>
>
>
> When I run my test, I see this failure:
>
> -------------
>
> at http://localhost:9080/js/require.js:1703: Can't find variable: Data, source: ReferenceError: Can't find variable: Data
>
> -------------
>
>
>
> I then added the following line before the first line:
>
> -------------
>
> var Data = window.Data || {};
>
> -------------
>
>
>
> This fixes the test. Running the app in my browser works fine both with or without this line.
>
>
>
> I know I haven't provided much code here, but is there anything obvious here that I'm missing?
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
require.js in a phantomjs test fails for code that works fine in production David Karr <davidmichaelkarr@gmail.com> - 2013-08-13 16:29 -0700
Re: require.js in a phantomjs test fails for code that works fine in production "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-08-13 16:52 -0700
Re: require.js in a phantomjs test fails for code that works fine in production David Karr <davidmichaelkarr@gmail.com> - 2013-08-13 17:27 -0700
Re: require.js in a phantomjs test fails for code that works fine in production Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-14 11:24 +0200
Re: require.js in a phantomjs test fails for code that works fine in production John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-14 14:48 +0100
Re: require.js in a phantomjs test fails for code that works fine in production Jim T. <x@y.z> - 2013-08-14 14:32 -0400
Re: require.js in a phantomjs test fails for code that works fine in production Tim Streater <timstreater@greenbee.net> - 2013-08-14 19:43 +0100
Re: require.js in a phantomjs test fails for code that works fine in production Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2013-08-15 18:51 -0300
Re: require.js in a phantomjs test fails for code that works fine in production Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-16 02:28 +0200
Re: require.js in a phantomjs test fails for code that works fine in production Martin Leese <please@see.Web.for.e-mail.INVALID> - 2013-08-15 20:12 -0600
Re: require.js in a phantomjs test fails for code that works fine in production John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-16 11:29 +0100
c.l.js (was: require.js in a phantomjs test fails for code that works fine in production) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-16 23:57 +0200
Re: c.l.js Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-18 10:17 +0200
Re: c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-18 15:14 +0100
Re: c.l.js (was: require.js in a phantomjs test fails for code that works fine in production) John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-18 15:51 +0100
Re: c.l.js Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-18 17:14 +0200
Re: c.l.js Tim Streater <timstreater@greenbee.net> - 2013-08-18 16:44 +0100
Re: c.l.js Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-18 17:52 +0200
Re: c.l.js Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-18 19:28 +0200
Re: c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-19 15:42 +0100
Re: c.l.js Andrew Poulos <ap_prog@hotmail.com> - 2013-08-20 06:58 +1000
Re: c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-20 16:10 +0100
Re: c.l.js Andrew Poulos <ap_prog@hotmail.com> - 2013-08-21 07:55 +1000
[OT] How to find messages by ID (was: c.l.js) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-21 06:47 +0200
Re: [OT] How to find messages by ID (was: c.l.js) John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-21 15:50 +0100
Re: [OT] How to find messages by ID (was: c.l.js) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-21 23:13 +0200
Re: [OT] How to find messages by ID (was: c.l.js) John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-22 11:05 +0100
Quoting in c.l.js (was: [OT] How to find messages by ID) Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-22 15:06 +0200
Re: Quoting in c.l.js (was: [OT] How to find messages by ID) John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-24 10:05 +0100
Re: Quoting in c.l.js Christoph Michael Becker <cmbecker69@arcor.de> - 2013-09-01 22:32 +0200
Re: Quoting in c.l.js Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-09-02 00:08 +0200
Re: Quoting in c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-09-02 15:52 +0100
Re: c.l.js Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-20 01:06 +0200
Re: c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-20 16:14 +0100
Re: c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-19 16:07 +0100
Re: c.l.js Andrew Poulos <ap_prog@hotmail.com> - 2013-08-20 07:01 +1000
Re: c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-20 16:20 +0100
Re: c.l.js Andrew Poulos <ap_prog@hotmail.com> - 2013-08-21 08:02 +1000
Re: c.l.js Tim Streater <timstreater@greenbee.net> - 2013-08-20 23:29 +0100
Re: c.l.js Andrew Poulos <ap_prog@hotmail.com> - 2013-08-21 14:59 +1000
Re: c.l.js John Harris <niam@jghnorth.org.uk.invalid> - 2013-08-21 16:05 +0100
Re: c.l.js Andrew Poulos <ap_prog@hotmail.com> - 2013-08-22 07:43 +1000
[FAQ] “javascript” (was: require.js in a phantomjs test fails for code that works fine in production) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-18 11:36 +0200
Re: require.js in a phantomjs test fails for code that works fine in production Carlos Pedro <carlospedr@gmail.com> - 2013-08-15 04:28 -0700
Re: require.js in a phantomjs test fails for code that works fine in production richarduie@yahoo.com - 2013-08-18 08:21 -0700
csiph-web