How to get properties of SpecResult in the Jasmine? - javascript

How to get access to the status property of SpecResult type of Global in the afterEach block in the Jasmine ver. 4.5?
I'm using bare Jasmine (with no Protracktor or WebDriverIO) and Selenium. I'd like to take screenshots only for tests that failed.
How can I get access to the current test status in the afterEach block?
I've tried this:
let status = jasmine.getEnv.SpecResult.status
let status = jasmine.getEnv().SpecResult.status
let status = jasmine.SpecResult.status
let status = this.SpecResult.status
But all of these got or 'undefined' or 'cannot read property of ...'

Related

How do I fix the error TypeError: can't access property "isRoot", location is undefined in Firebase?

I have an issue where, when I use firebase storage, I get the error:
TypeError: can't access property "isRoot", location is undefined
I am using SvelteKit, and have tested (because location is a browser object) it in an onMount call, as well as checking the browser form $app/environment. I have found the error is caused by these lines, I believe the listAll function:
listAll(filesRef).then((list)=>{
list.items.forEach(item=>{
files.push({
filetype:item.name.split(".").at(-1).toString(),
name:item.name
});
});
});
For context, the files variable is a list of objects with the filetype and filename.
I render these in a list.
If it helps, here's the entire traceback:
list$2 requests.ts:182
list$1 reference.ts:406
listAllHelper reference.ts:361
listAll$1 reference.ts:343
listAll api.ts:257
instance +page.svelte:58
init index.mjs:2002
Page +page.svelte:791
createProxiedComponent svelte-hooks.js:341
ProxyComponent proxy.js:242
Proxy<+page> proxy.js:349
construct_svelte_component_dev index.mjs:2218
update root.svelte:274
update_slot_base index.mjs:98
update +layout.svelte:154
update index.mjs:1193
flush index.mjs:1160
promise callback*schedule_update index.mjs:1118
make_dirty index.mjs:1970
ctx index.mjs:2008
$$set root.svelte:581
get proxy.js:83
$set index.mjs:2109
key proxy.js:46
update client.js:320
navigate client.js:1077
goto client.js:182
goto client.js:1249
gotoNext +page.svelte:11
instance +page.svelte:18
registerStateListener auth_impl.ts:565
promise callback*registerStateListener auth_impl.ts:565
onAuthStateChanged auth_impl.ts:407
onAuthStateChanged index.ts:128
instance +page.svelte:17
run index.mjs:18
mount_component index.mjs:1939
flush index.mjs:1175
promise callback*schedule_update index.mjs:1118
make_dirty index.mjs:1970
ctx index.mjs:2008
$$set root.svelte:581
get proxy.js:83
$set index.mjs:2109
key proxy.js:46
update client.js:320
navigate client.js:1077
goto client.js:182
goto client.js:1249
default Goto.ts:3
instance +page.svelte:14
run index.mjs:18
mount_component index.mjs:1939
flush index.mjs:1175
init index.mjs:2034
Root root.svelte:633
createProxiedComponent svelte-hooks.js:341
ProxyComponent proxy.js:242
Proxy<Root> proxy.js:349
initialize client.js:374
_hydrate client.js:1630
start start.js:39
<anonymous> [page]:10039
I found the problem
I figured out that, when I define the filesRef variable using the ref function, I forgot to define the storage attribute.
Original Definition (broken):
let filesRef = ref(`/user-generated/${$user.uid}`);
New Definition (working):
const storage = getStorage(app);
let filesRef = ref(storage, `/user-generated/${$user.uid}`);
I think that this is a bit of a problem because I spent literal hours looking for this bug. I am puzzled by the fact that it only causes an error in the listAll function, and not one relating to the storage parameter missing in the ref function. I am further puzzled that it refers to the location variable in the browser, as if it needs to check if the path is root, but can't do that in the event that the storage attribute is missing. I also know that isRoot is not a part of the location API, so maybe Firebase is extending the location API? I have used devTools to find the script and it is of the type of the window.location, so maybe Firebase should add a check for this. If this is some error that doesn't occur in JavaScript, as I'm using Typescript, but I heavily doubt this is the problem, as Typescript is complied into normal JS.

client.guilds.cache.get(...). members.get It is not a function

I'm doing a command with cargo, this error comes and I can't understand it, here's the script:
const member = client.guilds.cache.get('980553630480474232').members.get(interaction.user.id);
And here is the error:
client.guilds.cache.get(...).members.get is not a function.
In v13, you need to use .cache.get(), if the error persists double check your guild ID.
If you encounter such an error try console.log() to see wich value is undefined, because such errors results from having undefined values.
And for future advice if you need a value more than once in your code define it first, in this case use
const guild = client.guilds.cache.get('980553630480474232');
const member = guild.members.cache.get('ID')
Side Note: If this is a command file, you can directly get the guild using:
interaction.guild.members.get(interaction.user.id)

Matcher error: received value must not be null nor undefined

I am using expect in typescript to write an assertion while writing a Then step definition using typescript in in playwright
I have assigned an the class on this url https://www.gov.uk/help/accessibility-statement to confirm I can see accessibility statement when I land on the page.
I then get an undefined error when I run my tests.
Code written:-
import expect from "expect";
Then("I expect to be on the accessibility page", async function(
this: OurWorld
)
{
const {page} = this;
// eslint-disable-next-line no-debugger
const headMessage =await page?.$(".gem-c-title__text.govuk-heading-xl")
console.log(headMessage)
expect (headMessage).toContainEqual(("Accessibility statement")
);
});
I would like to check that the accessibility icon on the accessibility page contains the text accessibility.
The error I am getting back is this:-
× Then I expect to be on the accessibility page # step-definitions\feature.step-definitions.ts:28
Error: expect(received).toContainEqual(expected) // deep equality
Matcher error: received value must not be null nor undefined
Thank you for your help

How to mock object in mocha unittest?

In my reactjs component I have a method called getContainer(doc) with this line:
let w = Math.max(doc.documentElement.clientWidth, window.innerWidth);
It takes 1 parameter called doc: htmldocument. In my mocha unittest I got:
let mockDoc = {documentElement: {clientWidth:100}}
let res = wrapper.instance().getContainer(mockDoc);
When I run the test I still get an error , how can I fix this?
Error:
TypeError: Cannot read property 'clientWidth' of undefined
you can use an visual dom library like jsdom,for more details you can see jsdom.it is simple to use.here is a demo by enzyme

js-test-driver - How to get name of the running Test and TestCase in the setUp method?

I would like to know how we can get the name of the running test, name of the test case, and test result (whether test has passed or failed).
Following is the code example:
MyTestCase= TestCase("MyTestCase");
MyTestCase.prototype.setUp = function()
{
// print name of the test => testA
// print name of the testcase => MyTestCase
}
MyTestCase.prototype.testA= function()
{
//do something
}
MyTestCase.prototype.tearDown = function()
{
//result of the test => passed or failed??
}
I have used JSTestDriver with the QUnit Test runner which display name of the running test, name of the test case, and test result (whether test has passed or failed).
http://qunitjs.com/
Below is the adapter:
https://code.google.com/p/js-test-driver/wiki/QUnitAdapter
JsTestDriver has a flag called --testOutput , which specifies the path of where to store the results. You can find the test name, test case, and whether it passed or failed on there. It comes as an xml.

Categories