You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`The rating option must be a boolean. Please use true or false.\nSee https://developers.thegreenwebfoundation.org/co2js/options/ to learn more about the options available in CO2.js.`
89
+
);
90
+
}
91
+
92
+
// This flag checks to see if the model itself has a rating system.
93
+
constallowRatings=!!this.model.allowRatings;
94
+
84
95
/** @private */
85
96
this._segment=options?.results==="segment";
97
+
// This flag is set by the user to enable the rating system.
98
+
this._rating=options?.rating===true;
99
+
100
+
// The rating system is only supported in the Sustainable Web Design Model.
101
+
if(!allowRatings&&this._rating){
102
+
thrownewError(
103
+
`The rating system is not supported in the model you are using. Try using the Sustainable Web Design model instead.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`
104
+
);
105
+
}
86
106
}
87
107
88
108
/**
@@ -95,7 +115,7 @@ class CO2 {
95
115
* @return {number|CO2EstimateComponentsPerByte} the amount of CO2 in grammes or its separate components
`The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`
Copy file name to clipboardExpand all lines: src/co2.test.js
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -211,6 +211,22 @@ describe("co2", () => {
211
211
`The perVisit() method is not supported in the model you are using. Try using perByte() instead.\nSee https://developers.thegreenwebfoundation.org/co2js/methods/ to learn more about the methods available in CO2.js.`
212
212
);
213
213
});
214
+
215
+
it("throws an error if using the rating system with OneByte",()=>{
216
+
expect(()=>{
217
+
co2=newCO2({model: "1byte",rating: true});
218
+
}).toThrowError(
219
+
`The rating system is not supported in the model you are using. Try using the Sustainable Web Design model instead.\nSee https://developers.thegreenwebfoundation.org/co2js/models/ to learn more about the models available in CO2.js.`
220
+
);
221
+
});
222
+
223
+
it("throws an error if the rating parameter is not a boolean",()=>{
224
+
expect(()=>{
225
+
co2=newCO2({rating: "false"});
226
+
}).toThrowError(
227
+
`The rating option must be a boolean. Please use true or false.\nSee https://developers.thegreenwebfoundation.org/co2js/options/ to learn more about the options available in CO2.js.`
228
+
);
229
+
});
214
230
});
215
231
216
232
// Test that grid intensity data can be imported and used
0 commit comments