Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
7a8d83a1
Commit
7a8d83a1
authored
Dec 05, 2012
by
valera-rozuvan
Committed by
Valera Rozuvan
Jan 03, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work on RequireJS Jasmine test.
parent
c5cd67a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
1 deletions
+41
-1
lms/static/coffee/spec/requirejs_spec.coffee
+41
-1
No files found.
lms/static/coffee/spec/requirejs_spec.coffee
View file @
7a8d83a1
describe
"RequireJS namespacing"
,
->
beforeEach
->
#
# * Jasmine does not provide a way to use the typeof operator. We need
# * to create our own custom matchers so that a TypeError is not thrown.
#
@
addMatchers
requirejsTobeUndefined
:
->
typeof
requirejs
is
"undefined"
...
...
@@ -16,6 +21,10 @@ describe "RequireJS namespacing", ->
expect
(
window
.
RequireJS
).
toEqual
jasmine
.
any
(
Object
)
it
"check that requirejs(), require(), and define() are not in the global namespace"
,
->
# The custom matchers that we defined in the beforeEach() function do
# not operate on an object. We pass a dummy empty object {} not to
# confuse Jasmine.
expect
({}).
requirejsTobeUndefined
()
expect
({}).
requireTobeUndefined
()
expect
({}).
defineTobeUndefined
()
...
...
@@ -27,23 +36,54 @@ describe "RequireJS namespacing", ->
describe
"RequireJS module creation"
,
->
inDefineCallback
=
undefined
inRequireCallback
=
undefined
it
"check that we can use RequireJS define() and require() a module"
,
->
it
"check that we can use RequireJS to define() and require() a module"
,
->
# Because Require JS works asynchronously when defining and requiring
# modules, we need to use the special Jasmine functions runs(), and
# waitsFor() to set up this test.
runs
->
# Initialize the variable that we will test for. They will be set
# to true in the appropriate callback functions called by Require
# JS. If their values do not change, this will mean that something
# is not working as is intended.
inDefineCallback
=
false
inRequireCallback
=
false
# Define our test module.
RequireJS
.
define
"test_module"
,
[],
->
inDefineCallback
=
true
# This module returns an object. It can be accessed via the
# Require JS require() function.
module_status
:
"OK"
# Require our defined test module.
RequireJS
.
require
[
"test_module"
],
(
test_module
)
->
inRequireCallback
=
true
# If our test module was defined properly, then we should
# be able to get the object it returned, and query some
# property.
expect
(
test_module
.
module_status
).
toBe
"OK"
# We will wait for a specified amount of time (1 second), before
# checking if our module was defined and that we were able to
# require() the module.
waitsFor
(
->
# If at least one of the callback functions was not reached, we
# fail this test.
return
false
if
(
inDefineCallback
isnt
true
)
or
(
inRequireCallback
isnt
true
)
# Both of the callbacks were reached.
true
),
"We should eventually end up in the defined callback"
,
1000
# The final test behavior, after waitsFor() finishes waiting.
runs
->
expect
(
inDefineCallback
).
toBeTruthy
()
expect
(
inRequireCallback
).
toBeTruthy
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment