Skip to content

Commit

Permalink
Add readystate constants on instances (closes #66)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Apr 17, 2017
1 parent d388bd9 commit f35e15d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/eventsource.js
Expand Up @@ -298,6 +298,10 @@ Object.defineProperty(EventSource, 'CONNECTING', {enumerable: true, value: 0})
Object.defineProperty(EventSource, 'OPEN', {enumerable: true, value: 1})
Object.defineProperty(EventSource, 'CLOSED', {enumerable: true, value: 2})

EventSource.prototype.CONNECTING = 0
EventSource.prototype.OPEN = 1
EventSource.prototype.CLOSED = 2

/**
* Emulates the W3C Browser based WebSocket interface using addEventListener.
*
Expand Down
12 changes: 12 additions & 0 deletions test/eventsource_test.js
Expand Up @@ -762,6 +762,18 @@ describe('readyState', function () {
assert.equal(2, EventSource.CLOSED)
})

it('has readystate constants on instances', function (done) {
var es = new EventSource('http://localhost:' + _port)
assert.equal(EventSource.CONNECTING, es.CONNECTING, 'constant CONNECTING missing/invalid')
assert.equal(EventSource.OPEN, es.OPEN, 'constant OPEN missing/invalid')
assert.equal(EventSource.CLOSED, es.CLOSED, 'constant CLOSED missing/invalid')

es.onerror = function () {
es.close()
done()
}
})

it('is CONNECTING before connection has been established', function (done) {
var es = new EventSource('http://localhost:' + _port)
assert.equal(EventSource.CONNECTING, es.readyState)
Expand Down

0 comments on commit f35e15d

Please sign in to comment.