Skip to content

How to add ProtectedSessionStorage to Tests? #493

Answered by egil
newbiE247 asked this question in Q&A
Discussion options

You must be logged in to vote

hi @newbiE247, moved this to QA instead of an issue.

Anyway, the ProtectedSessionStorage is unfortunately pretty hard to fake or mock in tests without encapsulating it like @Christian-Oleson suggests. Here is some entirely untested code that you can consider using to see if it works for you.

First we create an abstraction that has the same API surface as ProtectedSessionStorage. Lets call it IBrowserStorage. That is what your component should have injected into it instead of ProtectedSessionStorage. E.g. update your components to have this:

[Inject] public IBrowserStorage SessionStorage { get; set; }

Here is the IBrowserStorage file:

public interface IBrowserStorage
{        
    ValueTask 

Replies: 4 comments 12 replies

Comment options

You must be logged in to vote
1 reply
@newbiE247
Comment options

Comment options

You must be logged in to vote
2 replies
@newbiE247
Comment options

@egil
Comment options

Answer selected by newbiE247
Comment options

You must be logged in to vote
2 replies
@newbiE247
Comment options

@egil
Comment options

Comment options

You must be logged in to vote
7 replies
@newbiE247
Comment options

@egil
Comment options

@newbiE247
Comment options

@egil
Comment options

@newbiE247
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #492 on September 10, 2021 09:30.