Skip to content

Commit 2f98cea

Browse files
committed
Update test to verify expected data actually reported
1 parent fbdd523 commit 2f98cea

File tree

1 file changed

+105
-21
lines changed

1 file changed

+105
-21
lines changed

test/examples/angular.test.js

Lines changed: 105 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
11
/* globals expect */
22
/* globals describe */
33
/* globals it */
4-
/* globals sinon */
54

65
// Import Rollbar directly from the source
76
var Rollbar = require('/Users/brian/Development/rollbar.js/dist/rollbar.umd.js');
87

98
describe('Angular integration', function () {
10-
// We're not testing the full Angular app with real button clicks
11-
// because the compiled Angular app needs its dependencies to be served correctly.
12-
// Instead, we'll test the core Rollbar integration points manually.
9+
// Utility function to create a test-enabled Rollbar instance
10+
function createTestRollbar(capturePayload) {
11+
var rollbar = new Rollbar({
12+
accessToken: 'ROLLBAR_POST_CLIENT_ITEM_TOKEN',
13+
captureUncaught: true,
14+
// Override logging to test
15+
autoInstrument: false,
16+
// Override endpoint to prevent actual API calls
17+
endpoint: 'https://test.example.com/api',
18+
// Set log level to debug to catch all messages
19+
logLevel: 'debug'
20+
});
21+
22+
// Override the actual API call with our test hook
23+
var originalQueue = rollbar.client.queue.addItem;
24+
rollbar.client.queue.addItem = function(item, callback) {
25+
// Capture the payload for verification
26+
capturePayload(item);
27+
// Call the original to maintain proper behavior
28+
return originalQueue.call(this, item, callback);
29+
};
30+
31+
return rollbar;
32+
}
1333

1434
it('should correctly configure Rollbar with Angular config options', function () {
1535
// Verify the integration by evaluating the Rollbar configuration pattern
@@ -29,28 +49,92 @@ describe('Angular integration', function () {
2949
expect(rollbar.options.captureUnhandledRejections).to.equal(true);
3050
});
3151

32-
// Skip the tests that require XHR interception for now
33-
// Angular integration testing is better done with the real API
34-
// or with a more sophisticated mocking approach
35-
it('should support error handling for Angular apps', function() {
36-
// Verify we can create a Rollbar instance that would be used in Angular
37-
var rollbar = new Rollbar({
38-
accessToken: 'ROLLBAR_POST_CLIENT_ITEM_TOKEN',
39-
captureUncaught: true,
52+
it('should process and send errors with correct data', function() {
53+
var processedItem = null;
54+
55+
// Create a Rollbar instance with our test hook
56+
var rollbar = createTestRollbar(function(item) {
57+
processedItem = item;
4058
});
4159

42-
// Test that the error method exists and is a function
43-
expect(typeof rollbar.error).to.equal('function');
60+
// Create a test error
61+
var testError = new Error('Test Angular Error');
62+
var customData = { component: 'TestComponent' };
63+
64+
// Call error method
65+
rollbar.error(testError, customData);
66+
67+
// Verify the error was processed
68+
expect(processedItem).to.not.equal(null);
69+
70+
// Verify the error level is set correctly
71+
expect(processedItem.level).to.equal('error');
72+
73+
// Verify the error message is included
74+
expect(processedItem.body.trace.exception.message).to.equal('Test Angular Error');
75+
76+
// Verify custom data is included
77+
expect(processedItem.custom.component).to.equal('TestComponent');
4478
});
4579

46-
it('should support warning logging for Angular apps', function() {
47-
// Verify we can create a Rollbar instance that would be used in Angular
48-
var rollbar = new Rollbar({
49-
accessToken: 'ROLLBAR_POST_CLIENT_ITEM_TOKEN',
50-
captureUncaught: true,
80+
it('should process and send warnings with correct data', function() {
81+
var processedItem = null;
82+
83+
// Create a Rollbar instance with our test hook
84+
var rollbar = createTestRollbar(function(item) {
85+
processedItem = item;
86+
});
87+
88+
// Call warning method
89+
var warningMessage = 'Test Angular Warning';
90+
var customData = { severity: 'medium' };
91+
92+
rollbar.warning(warningMessage, customData);
93+
94+
// Verify the warning was processed
95+
expect(processedItem).to.not.equal(null);
96+
97+
// Verify the warning level is set correctly
98+
expect(processedItem.level).to.equal('warning');
99+
100+
// Verify the warning message is included
101+
expect(processedItem.body.message.body).to.equal('Test Angular Warning');
102+
103+
// Verify custom data is included
104+
expect(processedItem.custom.severity).to.equal('medium');
105+
});
106+
107+
it('should include Angular-specific properties in error data', function() {
108+
var processedItem = null;
109+
110+
// Create a Rollbar instance with our test hook
111+
var rollbar = createTestRollbar(function(item) {
112+
processedItem = item;
51113
});
52114

53-
// Test that the warning method exists and is a function
54-
expect(typeof rollbar.warning).to.equal('function');
115+
// Create an Angular-specific error with ngDebugContext
116+
var angularError = new Error('Angular Component Error');
117+
118+
// Create a custom object that includes Angular-specific context
119+
var customData = {
120+
ngDebugContext: {
121+
component: 'TestAngularComponent',
122+
context: { name: 'AngularContext' }
123+
}
124+
};
125+
126+
// Call error method with the custom data that includes Angular debug context
127+
rollbar.error(angularError, customData);
128+
129+
// Verify the error was processed
130+
expect(processedItem).to.not.equal(null);
131+
132+
// Verify the error message is included
133+
expect(processedItem.body.trace.exception.message).to.equal('Angular Component Error');
134+
135+
// Verify Angular-specific properties are included in custom data
136+
expect(typeof processedItem.custom.ngDebugContext).to.equal('object');
137+
expect(processedItem.custom.ngDebugContext.component).to.equal('TestAngularComponent');
138+
expect(processedItem.custom.ngDebugContext.context.name).to.equal('AngularContext');
55139
});
56140
});

0 commit comments

Comments
 (0)